結果

問題 No.1373 Directed Operations
ユーザー tonyu0tonyu0
提出日時 2021-02-05 23:30:22
言語 Rust
(1.72.1)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 868 bytes
コンパイル時間 843 ms
コンパイル使用メモリ 149,104 KB
実行使用メモリ 5,984 KB
最終ジャッジ日時 2023-09-15 10:56:03
合計ジャッジ時間 3,799 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 127 ms
5,200 KB
testcase_03 AC 4 ms
4,632 KB
testcase_04 AC 6 ms
5,440 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 140 ms
5,956 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 16 ms
4,380 KB
testcase_09 AC 20 ms
5,984 KB
testcase_10 AC 17 ms
5,116 KB
testcase_11 AC 5 ms
4,380 KB
testcase_12 AC 17 ms
5,040 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 142 ms
5,976 KB
testcase_15 AC 126 ms
5,104 KB
testcase_16 AC 141 ms
5,920 KB
testcase_17 AC 100 ms
4,628 KB
testcase_18 AC 59 ms
4,376 KB
testcase_19 AC 56 ms
4,380 KB
testcase_20 AC 79 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 - 1)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();
    let mut b = Vec::new();
    for i in 0..n - 1 {
        b.push((a[i], i));
    }
    b.sort();
    let mut ans = vec![0; n - 1];
    let mut now = 1;
    let mut ok = true;
    for &(v, i) in b.iter() {
        // v-1 >
        if now > v - 1 {
            ans[i] = now - (v - 1);
            now += 1;
        } else {
            ok = false;
            break;
        }
    }
    if ok {
        println!("YES");
        for &b in ans.iter() {
            println!("{}", b);
        }
    } else {
        println!("NO")
    }
}
0