結果

問題 No.1770 N言っちゃダメゲーム (6)
ユーザー koba-e964
提出日時 2022-01-02 23:00:35
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 3,658 bytes
コンパイル時間 29,158 ms
コンパイル使用メモリ 378,200 KB
実行使用メモリ 16,032 KB
最終ジャッジ日時 2025-01-08 19:47:20
合計ジャッジ時間 26,912 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 44
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

use std::cmp::*;
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;
}
}
}
#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }
// https://yukicoder.me/problems/no/1770 (4)
// last K+1 (K = 3 5, 9, 13, 17, 21, 25, 29, 33, 37,
    ...K = 4 6, 11, 16, 21, 26, 31, 36, ...K = 5 8, 14, 21, 27, 34, 40, ... )
// K+1 N (K + 1 = a + b a = b 2 ) 1 + (K+1 )
    
// losing 2K + O(1) O(K^2) 4K + O(1) DP
// a last b (a, b) a x != b x (a, x) winning
     [a, b] (a, b) losing x != b x (a + b, x) winning
    [a + b, b] a, b, c (b != c) [a, b] [a, c] (a, x) winning
     b [a, b] (a, b) losing [a, b] b
    (a, x) losing
// a [a, b] 2 (3 2 ) 使[a
    , b] 1 a (1, 1), ..., (1, K) a (a, b) losing
     b 1 (a, x) 1 <= x <= K x losing a + 1 <= c <= a + K c [c,
    b] 1 a N/K O(N)
// Tags: game, nim-like
fn main() {
let n: usize = get();
let k: usize = get();
let mut know = vec![vec![]; n + 1];
for i in 1..n + 1 {
let l = know[i].len();
if l == 0 {
for j in 1..min(n - i, k) + 1 {
know[i + j].push(j);
}
} else if l == 1 {
let j = know[i][0];
if i + j <= n {
know[i + j].push(j);
}
}
}
let mut seen = false;
for i in 1..min(n, k + 1) {
let l = know[n - i].len();
if l == 0 || (l == 1 && know[n - i][0] == i) {
println!("{}", i);
seen = true;
}
}
if !seen {
println!("0");
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0