結果
| 問題 | No.1765 While Shining | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2022-10-15 15:36:54 | 
| 言語 | Rust (1.83.0 + proconio) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 12 ms / 2,000 ms | 
| コード長 | 1,049 bytes | 
| コンパイル時間 | 12,703 ms | 
| コンパイル使用メモリ | 378,808 KB | 
| 実行使用メモリ | 7,168 KB | 
| 最終ジャッジ日時 | 2024-06-26 19:55:30 | 
| 合計ジャッジ時間 | 13,899 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 22 | 
ソースコード
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);
}
            
            
            
        