結果
問題 | No.1373 Directed Operations |
ユーザー | tenten |
提出日時 | 2023-04-17 09:36:12 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 485 ms / 2,000 ms |
コード長 | 2,361 bytes |
コンパイル時間 | 2,760 ms |
コンパイル使用メモリ | 84,304 KB |
実行使用メモリ | 54,424 KB |
最終ジャッジ日時 | 2024-04-20 16:07:36 |
合計ジャッジ時間 | 10,910 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 65 ms
37,568 KB |
testcase_01 | AC | 53 ms
37,332 KB |
testcase_02 | AC | 312 ms
51,236 KB |
testcase_03 | AC | 197 ms
47,424 KB |
testcase_04 | AC | 206 ms
46,704 KB |
testcase_05 | AC | 65 ms
37,976 KB |
testcase_06 | AC | 427 ms
53,976 KB |
testcase_07 | AC | 94 ms
38,896 KB |
testcase_08 | AC | 168 ms
42,924 KB |
testcase_09 | AC | 370 ms
48,216 KB |
testcase_10 | AC | 313 ms
48,340 KB |
testcase_11 | AC | 176 ms
42,564 KB |
testcase_12 | AC | 316 ms
48,472 KB |
testcase_13 | AC | 137 ms
41,208 KB |
testcase_14 | AC | 485 ms
54,424 KB |
testcase_15 | AC | 423 ms
51,596 KB |
testcase_16 | AC | 476 ms
53,940 KB |
testcase_17 | AC | 311 ms
51,804 KB |
testcase_18 | AC | 215 ms
45,760 KB |
testcase_19 | AC | 311 ms
46,796 KB |
testcase_20 | AC | 340 ms
48,980 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); Unit[] units = new Unit[n - 1]; for (int i = 0; i < n - 1; i++) { units[i] = new Unit(i, sc.nextInt()); } Arrays.sort(units); int[] ans = new int[n - 1]; for (int i = 0; i < n - 1; i++) { if (i + 1 < units[i].value) { System.out.println("NO"); return; } ans[units[i].idx] = i + 1 - units[i].value + 1; } System.out.println("YES"); System.out.println(String.join("\n", Arrays.stream(ans).mapToObj(String::valueOf).toArray(String[]::new))); } static class Unit implements Comparable<Unit> { int idx; int value; public Unit(int idx, int value) { this.idx = idx; this.value = value; } public int compareTo(Unit another) { return value - another.value; } } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }