結果

問題 No.769 UNOシミュレータ
ユーザー simansiman
提出日時 2022-02-03 12:52:31
言語 Rust
(1.77.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 1,725 bytes
コンパイル時間 10,052 ms
コンパイル使用メモリ 144,144 KB
実行使用メモリ 19,996 KB
最終ジャッジ日時 2023-09-02 03:11:33
合計ジャッジ時間 2,569 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 3 ms
4,384 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 22 ms
7,512 KB
testcase_13 AC 22 ms
7,504 KB
testcase_14 AC 22 ms
7,508 KB
testcase_15 AC 41 ms
13,612 KB
testcase_16 AC 42 ms
12,884 KB
testcase_17 AC 41 ms
12,916 KB
testcase_18 AC 61 ms
19,492 KB
testcase_19 AC 61 ms
19,996 KB
testcase_20 AC 60 ms
18,220 KB
testcase_21 AC 59 ms
18,152 KB
testcase_22 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}

fn read_line<T: std::str::FromStr>() -> Vec<T> {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.split_whitespace()
        .map(|x| x.parse().ok().unwrap())
        .collect()
}

fn main() {
    let n_m: Vec<i32> = read_line();
    let mut card_counter = vec![0; n_m[0] as usize];
    let mut draw_counter = vec![0; n_m[0] as usize];
    let mut cur = 0;
    let mut stack_cnt = 0;
    let mut direct = 1;
    let mut actions: Vec<String> = Vec::new();
    
    for i in 0..n_m[1] {
        let action: String = read();
        
        if i > 0 &&
            (actions[(i - 1) as usize] == "drawtwo" || actions[(i - 1) as usize] == "drawfour") &&
            action != actions[(i - 1) as usize] {
            draw_counter[cur as usize] += stack_cnt;
            cur = (cur + direct + n_m[0]) % n_m[0];
            stack_cnt = 0;
        }
        card_counter[cur as usize] += 1;
    
        if action == "number" {
            // NOOP
        } else if action == "drawtwo" {
            stack_cnt += 2;
        } else if action == "drawfour" {
            stack_cnt += 4;
        } else if action == "skip" {
            if i < n_m[1] - 1 {
                cur = (cur + direct + n_m[0]) % n_m[0];
            }
        } else if action == "reverse" {
            direct *= -1;
        }
        
        if i < n_m[1] - 1 {
            cur = (cur + direct + n_m[0]) % n_m[0];
        }
        actions.push(action);
    }
    
    println!("{} {}", cur + 1, card_counter[cur as usize] - draw_counter[cur as usize]);
}
0