結果

問題 No.1506 Unbalanced Pocky Game
ユーザー phsplsphspls
提出日時 2022-11-03 23:57:45
言語 Rust
(1.77.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 1,161 bytes
コンパイル時間 1,083 ms
コンパイル使用メモリ 152,504 KB
実行使用メモリ 34,312 KB
最終ジャッジ日時 2023-09-25 06:53:12
合計ジャッジ時間 5,361 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 20 ms
16,852 KB
testcase_05 AC 22 ms
19,544 KB
testcase_06 AC 14 ms
12,600 KB
testcase_07 AC 10 ms
9,336 KB
testcase_08 AC 15 ms
12,868 KB
testcase_09 AC 24 ms
20,284 KB
testcase_10 AC 25 ms
20,888 KB
testcase_11 AC 11 ms
9,652 KB
testcase_12 AC 10 ms
8,852 KB
testcase_13 AC 5 ms
5,492 KB
testcase_14 AC 11 ms
9,668 KB
testcase_15 AC 9 ms
8,308 KB
testcase_16 AC 24 ms
20,040 KB
testcase_17 AC 12 ms
10,456 KB
testcase_18 AC 8 ms
7,196 KB
testcase_19 AC 6 ms
6,392 KB
testcase_20 AC 24 ms
20,576 KB
testcase_21 AC 10 ms
8,848 KB
testcase_22 AC 17 ms
13,904 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 31 ms
27,240 KB
testcase_26 AC 43 ms
33,712 KB
testcase_27 AC 44 ms
34,084 KB
testcase_28 AC 43 ms
32,996 KB
testcase_29 AC 41 ms
33,192 KB
testcase_30 AC 44 ms
34,284 KB
testcase_31 AC 44 ms
34,312 KB
testcase_32 AC 43 ms
33,648 KB
testcase_33 AC 44 ms
33,536 KB
testcase_34 AC 42 ms
32,744 KB
testcase_35 AC 42 ms
32,736 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 1 ms
4,380 KB
testcase_45 AC 1 ms
4,380 KB
testcase_46 AC 17 ms
12,832 KB
testcase_47 AC 6 ms
5,500 KB
testcase_48 AC 8 ms
6,580 KB
testcase_49 AC 19 ms
15,036 KB
testcase_50 AC 16 ms
13,100 KB
testcase_51 AC 18 ms
14,452 KB
testcase_52 AC 15 ms
11,688 KB
testcase_53 AC 21 ms
16,848 KB
testcase_54 AC 9 ms
7,636 KB
testcase_55 AC 7 ms
5,788 KB
testcase_56 AC 6 ms
5,516 KB
testcase_57 AC 16 ms
13,084 KB
testcase_58 AC 6 ms
5,524 KB
testcase_59 AC 4 ms
4,380 KB
testcase_60 AC 11 ms
8,416 KB
testcase_61 AC 16 ms
12,500 KB
testcase_62 AC 13 ms
10,580 KB
testcase_63 AC 9 ms
8,172 KB
testcase_64 AC 18 ms
14,452 KB
testcase_65 AC 11 ms
8,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::VecDeque;

const INF: usize = 1usize << 60;

fn dfs(i: usize, j: usize, a: &Vec<usize>, dp: &mut Vec<Vec<usize>>) -> usize {
    if dp[i][j] < INF { return dp[i][j]; }
    if j == 0 {
        dp[i][j] = 1 - dfs(i-1, a[i-1], a, dp);
    } else {
        let left = dfs(i, 0, a, dp);
        let right = dfs(i-1, a[i-1], a, dp);
        if left == right {
            dp[i][j] = 1 - left;
        } else {
            dp[i][j] = 0;
        }
    }
    dp[i][j]
}

fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    let n: usize = n.trim().parse().unwrap();
    let mut a = String::new();
    std::io::stdin().read_line(&mut a).ok();
    let a: Vec<usize> = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();

    let a = a.into_iter().map(|v| if v == 1 { 0usize } else { 1usize }).collect::<Vec<_>>();
    let mut dp = vec![vec![INF; 2]; n];
    dp[0][0] = 0;
    dp[0][1] = 0;
    let mut deque = VecDeque::new();
    deque.push_back((0, a[0]));
    dfs(n-1, a[n-1], &a, &mut dp);
    if dp[n-1][a[n-1]] == 0 {
        println!("Alice");
    } else {
        println!("Bob");
    }
}
0