結果

問題 No.1913 Periodic Comparison
ユーザー 37zigen37zigen
提出日時 2022-02-05 00:49:04
言語 Java21
(openjdk 21)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,671 bytes
コンパイル時間 4,298 ms
コンパイル使用メモリ 80,248 KB
実行使用メモリ 107,984 KB
最終ジャッジ日時 2023-09-02 06:56:50
合計ジャッジ時間 52,111 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 260 ms
59,188 KB
testcase_01 AC 208 ms
58,276 KB
testcase_02 AC 325 ms
59,812 KB
testcase_03 AC 262 ms
59,660 KB
testcase_04 AC 263 ms
59,324 KB
testcase_05 AC 261 ms
59,140 KB
testcase_06 AC 263 ms
58,952 KB
testcase_07 AC 268 ms
59,036 KB
testcase_08 AC 705 ms
60,892 KB
testcase_09 AC 1,754 ms
107,984 KB
testcase_10 AC 694 ms
61,464 KB
testcase_11 AC 1,661 ms
101,524 KB
testcase_12 AC 1,277 ms
90,800 KB
testcase_13 AC 619 ms
61,824 KB
testcase_14 AC 1,514 ms
98,728 KB
testcase_15 AC 1,688 ms
99,480 KB
testcase_16 AC 1,501 ms
100,196 KB
testcase_17 AC 718 ms
62,852 KB
testcase_18 AC 597 ms
61,348 KB
testcase_19 AC 1,700 ms
102,768 KB
testcase_20 AC 1,329 ms
92,864 KB
testcase_21 AC 1,676 ms
101,596 KB
testcase_22 RE -
testcase_23 AC 440 ms
60,460 KB
testcase_24 AC 1,521 ms
96,488 KB
testcase_25 AC 1,424 ms
101,080 KB
testcase_26 AC 1,609 ms
99,696 KB
testcase_27 AC 616 ms
61,400 KB
testcase_28 AC 676 ms
60,940 KB
testcase_29 AC 1,651 ms
102,344 KB
testcase_30 RE -
testcase_31 AC 448 ms
60,448 KB
testcase_32 AC 518 ms
61,024 KB
testcase_33 AC 631 ms
61,356 KB
testcase_34 AC 1,614 ms
99,736 KB
testcase_35 AC 1,655 ms
99,448 KB
testcase_36 AC 1,437 ms
102,212 KB
testcase_37 AC 1,707 ms
102,124 KB
testcase_38 AC 242 ms
59,144 KB
testcase_39 AC 207 ms
57,916 KB
testcase_40 AC 1,427 ms
95,032 KB
testcase_41 AC 1,704 ms
100,868 KB
testcase_42 AC 1,560 ms
103,464 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();
		int[] X=new int[N];
		int[] Y=new int[N];
		for (int i=0;i<N;++i) {
			X[i]=sc.nextInt();
		}
		for (int i=0;i<N;++i) {
			Y[i]=sc.nextInt();
		}
		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