結果

問題 No.769 UNOシミュレータ
ユーザー siman
提出日時 2022-02-03 12:52:31
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 1,725 bytes
コンパイル時間 13,001 ms
コンパイル使用メモリ 377,284 KB
実行使用メモリ 18,432 KB
最終ジャッジ日時 2024-06-11 09:49:48
合計ジャッジ時間 14,760 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

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