結果

問題 No.1913 Periodic Comparison
ユーザー 37zigen37zigen
提出日時 2022-02-10 04:41:33
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,813 ms / 2,000 ms
コード長 1,904 bytes
コンパイル時間 3,303 ms
コンパイル使用メモリ 77,616 KB
実行使用メモリ 108,096 KB
最終ジャッジ日時 2023-09-07 16:00:37
合計ジャッジ時間 57,038 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 257 ms
59,872 KB
testcase_01 AC 216 ms
59,176 KB
testcase_02 AC 334 ms
60,244 KB
testcase_03 AC 275 ms
59,436 KB
testcase_04 AC 268 ms
59,544 KB
testcase_05 AC 269 ms
57,168 KB
testcase_06 AC 270 ms
59,228 KB
testcase_07 AC 273 ms
59,400 KB
testcase_08 AC 729 ms
60,812 KB
testcase_09 AC 1,647 ms
102,716 KB
testcase_10 AC 691 ms
61,140 KB
testcase_11 AC 1,604 ms
99,800 KB
testcase_12 AC 1,322 ms
90,628 KB
testcase_13 AC 613 ms
59,252 KB
testcase_14 AC 1,497 ms
100,620 KB
testcase_15 AC 1,735 ms
101,336 KB
testcase_16 AC 1,455 ms
100,044 KB
testcase_17 AC 714 ms
62,760 KB
testcase_18 AC 633 ms
62,072 KB
testcase_19 AC 1,652 ms
101,476 KB
testcase_20 AC 1,373 ms
91,840 KB
testcase_21 AC 1,813 ms
107,968 KB
testcase_22 AC 574 ms
60,644 KB
testcase_23 AC 440 ms
60,344 KB
testcase_24 AC 1,523 ms
94,048 KB
testcase_25 AC 1,373 ms
100,628 KB
testcase_26 AC 1,608 ms
104,176 KB
testcase_27 AC 658 ms
62,552 KB
testcase_28 AC 690 ms
61,360 KB
testcase_29 AC 1,719 ms
101,332 KB
testcase_30 AC 1,605 ms
108,008 KB
testcase_31 AC 444 ms
60,444 KB
testcase_32 AC 514 ms
61,736 KB
testcase_33 AC 635 ms
60,552 KB
testcase_34 AC 1,732 ms
101,328 KB
testcase_35 AC 1,661 ms
100,512 KB
testcase_36 AC 1,556 ms
108,004 KB
testcase_37 AC 1,729 ms
108,096 KB
testcase_38 AC 258 ms
59,300 KB
testcase_39 AC 222 ms
58,812 KB
testcase_40 AC 1,368 ms
95,152 KB
testcase_41 AC 1,616 ms
100,304 KB
testcase_42 AC 1,687 ms
100,408 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] <= 1e6)) throw new AssertionError();
		}
		for (int i=0;i<N;++i) {
			Y[i]=sc.nextInt();
			if (!(0 <= Y[i] && Y[i] <= 1e6)) 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 && !que.isEmpty()){
			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() || (time > 0 && 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