Skip to content

Commit

Permalink
Add atcoder/abc303/a.rs atcoder/abc303/b.rs atcoder/abc303/remain.txt…
Browse files Browse the repository at this point in the history
… atcoder/abc308/a.rs atcoder/abc308/b.rs atcoder/abc308/c.rs atcoder/abc308/remain.txt atcoder/abc331/a.rs atcoder/abc331/b.rs atcoder/abc331/remain.txt
  • Loading branch information
koba-e964 committed Apr 26, 2024
1 parent fbc76c7 commit 7ad8871
Show file tree
Hide file tree
Showing 10 changed files with 320 additions and 0 deletions.
25 changes: 25 additions & 0 deletions atcoder/abc303/a.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
fn getline() -> String {
let mut ret = String::new();
std::io::stdin().read_line(&mut ret).ok().unwrap();
ret
}

fn main() {
getline();
let s = getline();
let t = getline();
let f = |x| if x == 'l' {
'1'
} else if x == 'o' {
'0'
} else {
x
};
for (s, t) in s.chars().zip(t.chars()) {
if f(s) != f(t) {
println!("No");
return;
}
}
println!("Yes");
}
54 changes: 54 additions & 0 deletions atcoder/abc303/b.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
($($r:tt)*) => {
let stdin = std::io::stdin();
let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
let mut next = move || -> String{
bytes.by_ref().map(|r|r.unwrap() as char)
.skip_while(|c|c.is_whitespace())
.take_while(|c|!c.is_whitespace())
.collect()
};
input_inner!{next, $($r)*}
};
}

macro_rules! input_inner {
($next:expr) => {};
($next:expr,) => {};
($next:expr, $var:ident : $t:tt $($r:tt)*) => {
let $var = read_value!($next, $t);
input_inner!{$next $($r)*}
};
}

macro_rules! read_value {
($next:expr, [ $t:tt ; $len:expr ]) => {
(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
};
($next:expr, usize1) => (read_value!($next, usize) - 1);
($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

fn main() {
input! {
n: usize, m: usize,
a: [[usize1; n]; m],
}
let mut nei = vec![vec![false; n]; n];
for a in a {
for i in 0..n - 1 {
nei[a[i]][a[i + 1]] = true;
nei[a[i + 1]][a[i]] = true;
}
}
let mut ans = 0;
for i in 0..n {
for j in 0..i {
if !nei[i][j] {
ans += 1;
}
}
}
println!("{}", ans);
}
6 changes: 6 additions & 0 deletions atcoder/abc303/remain.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
c
d
e
f
g
ex
36 changes: 36 additions & 0 deletions atcoder/abc308/a.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use std::io::Read;

fn get_word() -> String {
let stdin = std::io::stdin();
let mut stdin=stdin.lock();
let mut u8b: [u8; 1] = [0];
loop {
let mut buf: Vec<u8> = Vec::with_capacity(16);
loop {
let res = stdin.read(&mut u8b);
if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
break;
} else {
buf.push(u8b[0]);
}
}
if buf.len() >= 1 {
let ret = String::from_utf8(buf).unwrap();
return ret;
}
}
}

fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn main() {
let mut s = vec![0; 8];
for i in 0..8 {
s[i] = get::<i32>();
}
if s.iter().all(|&s| 100 <= s && s <= 675 && s % 25 == 0) && (0..7).all(|i| s[i] <= s[i + 1]) {
println!("Yes");
} else {
println!("No");
}
}
57 changes: 57 additions & 0 deletions atcoder/abc308/b.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
use std::io::Read;

fn get_word() -> String {
let stdin = std::io::stdin();
let mut stdin=stdin.lock();
let mut u8b: [u8; 1] = [0];
loop {
let mut buf: Vec<u8> = Vec::with_capacity(16);
loop {
let res = stdin.read(&mut u8b);
if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
break;
} else {
buf.push(u8b[0]);
}
}
if buf.len() >= 1 {
let ret = String::from_utf8(buf).unwrap();
return ret;
}
}
}

fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn main() {
let n: usize = get();
let m: usize = get();
let mut c = vec![];
for _ in 0..n {
c.push(get_word());
}
let mut d = vec![];
for _ in 0..m {
d.push(get_word());
}
let mut p = vec![];
for _ in 0..m + 1 {
p.push(get::<i32>());
}
let mut ans = 0;
for c in c {
let mut idx = m;
for i in 0..m {
if c == d[i] {
idx = i;
break;
}
}
if idx == m {
ans += p[0];
} else {
ans += p[idx + 1];
}
}
println!("{}", ans);
}
38 changes: 38 additions & 0 deletions atcoder/abc308/c.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use std::io::Read;

fn get_word() -> String {
let stdin = std::io::stdin();
let mut stdin=stdin.lock();
let mut u8b: [u8; 1] = [0];
loop {
let mut buf: Vec<u8> = Vec::with_capacity(16);
loop {
let res = stdin.read(&mut u8b);
if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
break;
} else {
buf.push(u8b[0]);
}
}
if buf.len() >= 1 {
let ret = String::from_utf8(buf).unwrap();
return ret;
}
}
}

fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn main() {
let n: usize = get();
let mut a = vec![];
for i in 0..n {
let x: i64 = get();
let y: i64 = get();
a.push((x, y, i));
}
a.sort_by(|(ax, ay, ai), (bx, by, bi)| (ay * bx).cmp(&(ax * by)).then(ai.cmp(bi)));
for i in 0..n {
print!("{} ", a[i].2 + 1);
}
}
5 changes: 5 additions & 0 deletions atcoder/abc308/remain.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
d
e
f
g
ex
42 changes: 42 additions & 0 deletions atcoder/abc331/a.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use std::io::Read;

fn get_word() -> String {
let stdin = std::io::stdin();
let mut stdin=stdin.lock();
let mut u8b: [u8; 1] = [0];
loop {
let mut buf: Vec<u8> = Vec::with_capacity(16);
loop {
let res = stdin.read(&mut u8b);
if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
break;
} else {
buf.push(u8b[0]);
}
}
if buf.len() >= 1 {
let ret = String::from_utf8(buf).unwrap();
return ret;
}
}
}

fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn main() {
let mm: i32 = get();
let dd: i32 = get();
let mut y: i32 = get();
let mut m: i32 = get();
let mut d: i32 = get();
d += 1;
if d > dd {
d = 1;
m += 1;
}
if m > mm {
m = 1;
y += 1;
}
println!("{y} {m} {d}");
}
52 changes: 52 additions & 0 deletions atcoder/abc331/b.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use std::io::Read;

fn get_word() -> String {
let stdin = std::io::stdin();
let mut stdin=stdin.lock();
let mut u8b: [u8; 1] = [0];
loop {
let mut buf: Vec<u8> = Vec::with_capacity(16);
loop {
let res = stdin.read(&mut u8b);
if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
break;
} else {
buf.push(u8b[0]);
}
}
if buf.len() >= 1 {
let ret = String::from_utf8(buf).unwrap();
return ret;
}
}
}

fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn main() {
let n: usize = get();
let s: i32 = get();
let m: i32 = get();
let l: i32 = get();
let mut ans = vec![0; n + 1];
for i in 1..n + 1 {
let mut me = ans[i - 1] + s;
for j in 1..7 {
if i >= j {
me = std::cmp::min(me, ans[i - j] + s);
}
}
for j in 1..9 {
if i >= j {
me = std::cmp::min(me, ans[i - j] + m);
}
}
for j in 1..13 {
if i >= j {
me = std::cmp::min(me, ans[i - j] + l);
}
}
ans[i] = me;
}
println!("{}", ans[n]);
}
5 changes: 5 additions & 0 deletions atcoder/abc331/remain.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
c
d
e
f
g

0 comments on commit 7ad8871

Please sign in to comment.