結果
問題 | No.1373 Directed Operations |
ユーザー | tenten |
提出日時 | 2023-02-17 15:36:46 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 451 ms / 2,000 ms |
コード長 | 2,373 bytes |
コンパイル時間 | 3,196 ms |
コンパイル使用メモリ | 82,200 KB |
実行使用メモリ | 65,808 KB |
最終ジャッジ日時 | 2023-09-26 14:42:23 |
合計ジャッジ時間 | 12,536 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 60 ms
51,016 KB |
testcase_01 | AC | 45 ms
49,720 KB |
testcase_02 | AC | 287 ms
62,100 KB |
testcase_03 | AC | 174 ms
58,772 KB |
testcase_04 | AC | 193 ms
58,300 KB |
testcase_05 | AC | 59 ms
48,592 KB |
testcase_06 | AC | 437 ms
65,316 KB |
testcase_07 | AC | 86 ms
51,636 KB |
testcase_08 | AC | 158 ms
56,832 KB |
testcase_09 | AC | 332 ms
59,984 KB |
testcase_10 | AC | 314 ms
57,724 KB |
testcase_11 | AC | 171 ms
55,888 KB |
testcase_12 | AC | 309 ms
59,968 KB |
testcase_13 | AC | 119 ms
52,688 KB |
testcase_14 | AC | 451 ms
65,452 KB |
testcase_15 | AC | 414 ms
63,208 KB |
testcase_16 | AC | 421 ms
65,808 KB |
testcase_17 | AC | 301 ms
63,092 KB |
testcase_18 | AC | 203 ms
57,464 KB |
testcase_19 | AC | 287 ms
58,548 KB |
testcase_20 | AC | 337 ms
60,804 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(); Route[] routes = new Route[n - 1]; for(int i = 0; i < n - 1; i++) { routes[i] = new Route(i, sc.nextInt()); } Arrays.sort(routes); int[] ans = new int[n - 1]; for (int i = 1; i < n; i++) { if (routes[i - 1].value > i) { System.out.println("NO"); return; } ans[routes[i - 1].idx] = i - routes[i - 1].value + 1; } System.out.println("YES"); System.out.println(String.join("\n", Arrays.stream(ans).mapToObj(String::valueOf).toArray(String[]::new))); } static class Route implements Comparable<Route> { int idx; int value; public Route(int idx, int value) { this.idx = idx; this.value = value; } public int compareTo(Route 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(); } }