結果

問題 No.1765 While Shining
ユーザー phsplsphspls
提出日時 2022-10-15 15:36:54
言語 Rust
(1.77.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 1,049 bytes
コンパイル時間 864 ms
コンパイル使用メモリ 145,032 KB
実行使用メモリ 7,172 KB
最終ジャッジ日時 2023-09-09 02:41:36
合計ジャッジ時間 2,730 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 8 ms
5,320 KB
testcase_10 AC 12 ms
6,720 KB
testcase_11 AC 11 ms
6,184 KB
testcase_12 AC 11 ms
6,480 KB
testcase_13 AC 11 ms
6,056 KB
testcase_14 AC 13 ms
7,140 KB
testcase_15 AC 12 ms
7,032 KB
testcase_16 AC 12 ms
7,160 KB
testcase_17 AC 12 ms
7,172 KB
testcase_18 AC 13 ms
7,156 KB
testcase_19 AC 13 ms
7,028 KB
testcase_20 AC 12 ms
7,108 KB
testcase_21 AC 12 ms
7,116 KB
testcase_22 AC 12 ms
7,172 KB
testcase_23 AC 12 ms
7,124 KB
testcase_24 AC 8 ms
5,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 mut evens = vec![0isize; n];
    let mut odds = vec![0isize; n];
    for i in (0..n-1).step_by(2) {
        if odds[i] > 0 { continue; }
        let mut idx = i;
        while idx < n-1 && a[idx] == 1 - idx % 2 {
            idx += 1;
        }
        for j in i..idx {
            odds[j] = (idx - j) as isize;
        }
    }
    for i in (1..n-1).step_by(2) {
        if evens[i] > 0 { continue; }
        let mut idx = i;
        while idx < n-1 && a[idx] == idx % 2 {
            idx += 1;
        }
        for j in i..idx {
            evens[j] = (idx - j) as isize;
        }
    }
    let mut result = 0isize;
    for i in 0..n {
        result += if i % 2 == 1 { evens[i] } else { odds[i] };
    }
    println!("{}", result);
}
0