結果
問題 | No.1373 Directed Operations |
ユーザー |
![]() |
提出日時 | 2021-02-06 13:31:35 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 828 ms / 2,000 ms |
コード長 | 1,136 bytes |
コンパイル時間 | 2,386 ms |
コンパイル使用メモリ | 77,984 KB |
実行使用メモリ | 51,488 KB |
最終ジャッジ日時 | 2024-07-02 21:39:21 |
合計ジャッジ時間 | 15,393 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 19 |
ソースコード
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; } } }