結果
| 問題 |
No.1373 Directed Operations
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2024-07-25 17:25:30 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 416 ms / 2,000 ms |
| コード長 | 2,007 bytes |
| コンパイル時間 | 2,601 ms |
| コンパイル使用メモリ | 84,776 KB |
| 実行使用メモリ | 63,464 KB |
| 最終ジャッジ日時 | 2024-07-25 17:25:41 |
| 合計ジャッジ時間 | 9,940 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 19 |
ソースコード
import java.io.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int n = sc.nextInt();
PriorityQueue<Unit> units = new PriorityQueue<>();
for (int i = 0; i < n - 1; i++) {
units.add(new Unit(i, sc.nextInt()));
}
int[] ans = new int[n - 1];
for (int i = 2; i <= n; i++) {
Unit x = units.poll();
if (x.value >= i) {
System.out.println("NO");
return;
}
ans[x.idx] = i - x.value;
}
System.out.println("YES");
System.out.println(Arrays.stream(ans).mapToObj(String::valueOf).collect(Collectors.joining("\n")));
}
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 Scanner {
BufferedReader br;
StringTokenizer st = new StringTokenizer("");
StringBuilder sb = new StringBuilder();
public Scanner() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
} catch (Exception e) {
}
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String next() {
try {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
} catch (Exception e) {
e.printStackTrace();
} finally {
return st.nextToken();
}
}
}
tenten