結果
| 問題 |
No.1913 Periodic Comparison
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-02-05 01:05:04 |
| 言語 | Java (openjdk 23) |
| 結果 |
RE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,856 bytes |
| コンパイル時間 | 2,421 ms |
| コンパイル使用メモリ | 83,936 KB |
| 実行使用メモリ | 94,552 KB |
| 最終ジャッジ日時 | 2024-06-11 13:45:37 |
| 合計ジャッジ時間 | 49,073 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 38 RE * 2 |
ソースコード
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
class Main {
public static void main(String[] args) {
new Main().run();
}
void solve() {
Scanner sc=new Scanner(System.in);
PrintWriter pw=new PrintWriter(System.out);
HashMap<Integer, int[]> points=new HashMap<>();
int N=sc.nextInt();
if (!(1 <= N && N <= 2e5)) throw new AssertionError();
int[] X=new int[N];
int[] Y=new int[N];
for (int i=0;i<N;++i) {
X[i]=sc.nextInt();
if (!(0 <= X[i] && X[i] <= 1e7)) throw new AssertionError();
}
for (int i=0;i<N;++i) {
Y[i]=sc.nextInt();
if (!(0 <= Y[i] && Y[i] <= 1e7)) throw new AssertionError();
}
for (int i=0;i<N;++i) {
if (points.containsKey(Y[i])) {
System.out.println(-1);
return;
}
points.put(Y[i], new int[] {X[i], i});
}
class State {
int col;
int height;
public State(int col, int height) {
this.col=col;
this.height=height;
}
}
int[] ans=new int[N];
ArrayDeque<State> que=new ArrayDeque<>();
for (int i=0;i<N;++i) que.addLast(new State(-1, -1));
int time = (int)1e7;
while (time >= 0) {
State state = que.pollFirst();
if (points.containsKey(time)) {
if (state.col != -1) {
System.out.println(-1);
return;
}
int[] xi=points.get(time);
state.col = xi[1];
state.height = xi[0];
} else {
if (state.col != -1) state.height--;
}
if (state.height == 0) {
ans[state.col] = time;
} else {
que.addLast(state);
}
--time;
}
if (!que.isEmpty()) {
System.out.println(-1);
return;
}
for (int i=0;i<N;++i) {
pw.print(ans[i]+(i==N-1?"\n":" "));
}
pw.close();
}
void run() {
solve();
}
static void tr(Object...objects) {
System.out.println(Arrays.deepToString(objects));
}
}