結果
| 問題 | No.1687 What the Heck? | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2021-09-24 23:27:00 | 
| 言語 | Rust (1.83.0 + proconio) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 899 bytes | 
| コンパイル時間 | 15,502 ms | 
| コンパイル使用メモリ | 377,744 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-07-05 11:34:40 | 
| 合計ジャッジ時間 | 12,998 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 14 WA * 4 | 
ソースコード
use std::io::*;
fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (0..n)
        .map(|_| itr.next().unwrap().parse::<usize>().unwrap() - 1)
        .collect();
    let mut used = vec![false; n + 1];
    let mut ans = 0;
    for i in (0..n).rev() {
        let mut j = a[i] + 1;
        while j < n && used[j] {
            j += 1;
        }
        if j != n {
            used[j] = true;
            ans += i + 1;
        } else if !used[a[i]] {
            used[a[i]] = true;
        } else {
            for k in 0..n {
                if !used[k] {
                    used[k] = true;
                    break;
                }
            }
            ans -= i + 1;
        }
    }
    println!("{}", ans);
}
            
            
            
        