結果

問題 No.1373 Directed Operations
ユーザー tentententen
提出日時 2021-02-06 13:31:35
言語 Java21
(openjdk 21)
結果
AC  
実行時間 703 ms / 2,000 ms
コード長 1,136 bytes
コンパイル時間 4,723 ms
コンパイル使用メモリ 74,112 KB
実行使用メモリ 67,292 KB
最終ジャッジ日時 2023-09-15 19:55:05
合計ジャッジ時間 15,579 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,508 KB
testcase_01 AC 120 ms
55,832 KB
testcase_02 AC 523 ms
63,696 KB
testcase_03 AC 495 ms
62,608 KB
testcase_04 AC 517 ms
62,492 KB
testcase_05 AC 120 ms
55,892 KB
testcase_06 AC 670 ms
67,116 KB
testcase_07 AC 199 ms
58,440 KB
testcase_08 AC 289 ms
60,180 KB
testcase_09 AC 622 ms
65,544 KB
testcase_10 AC 572 ms
63,380 KB
testcase_11 AC 360 ms
61,296 KB
testcase_12 AC 608 ms
63,324 KB
testcase_13 AC 276 ms
60,532 KB
testcase_14 AC 671 ms
66,948 KB
testcase_15 AC 636 ms
67,080 KB
testcase_16 AC 703 ms
67,292 KB
testcase_17 AC 549 ms
62,744 KB
testcase_18 AC 390 ms
60,860 KB
testcase_19 AC 472 ms
60,732 KB
testcase_20 AC 523 ms
61,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Idx[] idxes = new Idx[n - 1];
        for (int i = 0; i < n - 1; i++) {
            idxes[i] = new Idx(i, sc.nextInt());
        }
        Arrays.sort(idxes);
        int[] ans = new int[n - 1];
        for (int i = 0; i < n - 1; i++) {
            if (idxes[i].value > i + 1) {
                System.out.println("NO");
                return;
            }
            ans[idxes[i].idx] = i + 2 - idxes[i].value;
        }
        StringBuilder sb = new StringBuilder();
        sb.append("YES").append("\n");
        for (int i = 0; i < n - 1; i++) {
            sb.append(ans[i]).append("\n");
        }
        System.out.print(sb);
    }
    
    static class Idx implements Comparable<Idx> {
        int idx;
        int value;
        
        public Idx(int idx, int value) {
            this.idx = idx;
            this.value = value;
        }
        
        public int compareTo(Idx another) {
            return value - another.value;
        }
    }
}
0