Skip to content

Commit

Permalink
tessoku-book a45, b45
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Nov 2, 2022
1 parent 89a1e3f commit e75c86b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
35 changes: 30 additions & 5 deletions tessoku-book/src/bin/a45.rs
@@ -1,10 +1,35 @@
use proconio::{input, marker::Usize1};
use proconio::{input, marker::Chars};

fn main() {
input! {
n: usize,
a: [Usize1; n],
_n: usize,
c: char,
a: Chars,
};
let ans = n - a.len();
println!("{}", ans);
// W: 0
// B: 1
// R: 2
//
// W + W = W = 0 + 0 = 0
// B + B = R = 1 + 1 = 2
// R + R = B = 2 + 2 = 1 (mod 3)
// W + B = B = 0 + 1 = 1
// W + R = R = 0 + 2 = 2
// B + R = W = 1 + 2 = 0 (mod 3)
let f = |ch: char| -> usize {
match ch {
'W' => 0,
'B' => 1,
'R' => 2,
_ => unreachable!(),
}
};

let mut sum = 0_usize;
for a_i in a {
sum += f(a_i);
sum %= 3;
}
let ans = sum == f(c);
println!("{}", if ans { "Yes" } else { "No" });
}
11 changes: 6 additions & 5 deletions tessoku-book/src/bin/b45.rs
@@ -1,10 +1,11 @@
use proconio::{input, marker::Usize1};
use proconio::input;

fn main() {
input! {
n: usize,
a: [Usize1; n],
a: i64,
b: i64,
c: i64,
};
let ans = n - a.len();
println!("{}", ans);
let ans = (a + b + c) == 0;
println!("{}", if ans { "Yes" } else { "No" });
}

0 comments on commit e75c86b

Please sign in to comment.