結果

問題 No.1373 Directed Operations
ユーザー phsplsphspls
提出日時 2022-10-07 23:56:28
言語 Rust
(1.77.0)
結果
AC  
実行時間 203 ms / 2,000 ms
コード長 991 bytes
コンパイル時間 5,082 ms
コンパイル使用メモリ 155,784 KB
実行使用メモリ 14,960 KB
最終ジャッジ日時 2023-09-03 16:40:31
合計ジャッジ時間 9,661 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 143 ms
5,384 KB
testcase_03 AC 16 ms
5,420 KB
testcase_04 AC 11 ms
5,736 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 203 ms
14,960 KB
testcase_07 AC 5 ms
4,380 KB
testcase_08 AC 21 ms
4,376 KB
testcase_09 AC 52 ms
14,476 KB
testcase_10 AC 58 ms
13,088 KB
testcase_11 AC 12 ms
4,688 KB
testcase_12 AC 31 ms
9,020 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 180 ms
10,256 KB
testcase_15 AC 158 ms
9,080 KB
testcase_16 AC 181 ms
9,884 KB
testcase_17 AC 112 ms
5,740 KB
testcase_18 AC 64 ms
4,380 KB
testcase_19 AC 79 ms
6,920 KB
testcase_20 AC 108 ms
9,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::{BTreeSet, BTreeMap};


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 points = (1..n).collect::<BTreeSet<usize>>();
    let mut amap = BTreeMap::new();
    for i in 0..n-1 { amap.entry(a[i]).or_insert(vec![]).push(i); }
    let mut result = vec![0usize; n-1];
    for (&span, ps) in amap.iter().rev() {
        for i in 0..ps.len() {
            let nextp = points.range(span..).nth(0);
            if let Some(&np) = nextp {
                result[ps[i]] = np - span;
                points.remove(&np);
            } else {
                println!("NO");
                return;
            }
        }
    }
    println!("YES");
    for &v in result.iter() {
        println!("{}", v + 1);
    }
}
0