Skip to content

Commit

Permalink
tessoku-book a34, b34
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Oct 20, 2022
1 parent 3cc3ec6 commit fea1811
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
29 changes: 25 additions & 4 deletions tessoku-book/src/bin/a34.rs
@@ -1,10 +1,31 @@
use proconio::{input, marker::Usize1};
use proconio::input;

fn main() {
input! {
n: usize,
a: [Usize1; n],
x: usize,
y: usize,
a: [usize; n],
};
let ans = n - a.len();
println!("{}", ans);

let max_a_i = *a.iter().max().unwrap();

let mut grundy = vec![0; max_a_i + 1];
for i in 0..=max_a_i {
let mut transit = vec![false; 3];
if i >= x {
transit[grundy[i - x]] = true;
}
if i >= y {
transit[grundy[i - y]] = true;
}
grundy[i] = transit.iter().copied().position(|v| !v).unwrap();
}

let ans = a
.iter()
.copied()
.fold(0_usize, |acc, a_i| acc ^ grundy[a_i])
!= 0;
println!("{}", if ans { "First" } else { "Second" });
}
27 changes: 23 additions & 4 deletions tessoku-book/src/bin/b34.rs
@@ -1,10 +1,29 @@
use proconio::{input, marker::Usize1};
use proconio::input;

fn main() {
input! {
n: usize,
a: [Usize1; n],
x: usize,
y: usize,
a: [usize; n],
};
let ans = n - a.len();
println!("{}", ans);

let max_a_i = 5;
let mut grundy = vec![0; max_a_i + 1];
for i in 0..=max_a_i {
let mut transit = vec![false; 3];
if i >= x {
transit[grundy[i - x]] = true;
}
if i >= y {
transit[grundy[i - y]] = true;
}
grundy[i] = transit.iter().copied().position(|v| !v).unwrap();
}
let ans = a
.iter()
.copied()
.fold(0_usize, |acc, a_i| acc ^ grundy[a_i % 5])
!= 0;
println!("{}", if ans { "First" } else { "Second" });
}

0 comments on commit fea1811

Please sign in to comment.