結果

問題 No.1913 Periodic Comparison
ユーザー 37zigen37zigen
提出日時 2022-02-05 01:05:04
言語 Java21
(openjdk 21)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,856 bytes
コンパイル時間 3,523 ms
コンパイル使用メモリ 90,824 KB
実行使用メモリ 107,328 KB
最終ジャッジ日時 2023-09-02 06:57:43
合計ジャッジ時間 51,674 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 259 ms
59,284 KB
testcase_01 AC 204 ms
58,472 KB
testcase_02 AC 322 ms
60,160 KB
testcase_03 AC 260 ms
57,932 KB
testcase_04 AC 260 ms
60,088 KB
testcase_05 AC 261 ms
59,056 KB
testcase_06 AC 265 ms
59,108 KB
testcase_07 AC 266 ms
59,520 KB
testcase_08 AC 731 ms
60,888 KB
testcase_09 AC 1,710 ms
107,328 KB
testcase_10 AC 694 ms
61,028 KB
testcase_11 AC 1,543 ms
99,728 KB
testcase_12 AC 1,214 ms
89,528 KB
testcase_13 AC 608 ms
62,068 KB
testcase_14 AC 1,440 ms
97,928 KB
testcase_15 AC 1,578 ms
100,476 KB
testcase_16 AC 1,375 ms
99,108 KB
testcase_17 AC 704 ms
61,248 KB
testcase_18 AC 587 ms
61,028 KB
testcase_19 AC 1,601 ms
103,204 KB
testcase_20 AC 1,359 ms
91,240 KB
testcase_21 AC 1,555 ms
100,988 KB
testcase_22 RE -
testcase_23 AC 439 ms
60,736 KB
testcase_24 AC 1,447 ms
96,344 KB
testcase_25 AC 1,270 ms
101,200 KB
testcase_26 AC 1,387 ms
99,740 KB
testcase_27 AC 614 ms
62,204 KB
testcase_28 AC 680 ms
61,220 KB
testcase_29 AC 1,526 ms
101,604 KB
testcase_30 RE -
testcase_31 AC 448 ms
60,172 KB
testcase_32 AC 519 ms
62,760 KB
testcase_33 AC 625 ms
60,564 KB
testcase_34 AC 1,509 ms
100,892 KB
testcase_35 AC 1,601 ms
99,500 KB
testcase_36 AC 1,367 ms
100,052 KB
testcase_37 AC 1,556 ms
100,132 KB
testcase_38 AC 244 ms
59,596 KB
testcase_39 AC 210 ms
58,548 KB
testcase_40 AC 1,384 ms
95,212 KB
testcase_41 AC 1,596 ms
100,940 KB
testcase_42 AC 1,481 ms
100,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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));
	}

}
0