結果

問題 No.241 出席番号(1)
ユーザー 37zigen37zigen
提出日時 2020-03-30 03:59:19
言語 Java21
(openjdk 21)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 1,188 bytes
コンパイル時間 4,627 ms
コンパイル使用メモリ 83,144 KB
実行使用メモリ 57,812 KB
最終ジャッジ日時 2023-08-30 20:15:52
合計ジャッジ時間 10,678 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
56,112 KB
testcase_01 AC 125 ms
56,032 KB
testcase_02 AC 124 ms
55,780 KB
testcase_03 AC 122 ms
56,120 KB
testcase_04 AC 133 ms
56,236 KB
testcase_05 AC 134 ms
55,992 KB
testcase_06 AC 132 ms
55,592 KB
testcase_07 AC 124 ms
55,504 KB
testcase_08 AC 122 ms
56,088 KB
testcase_09 AC 122 ms
56,108 KB
testcase_10 AC 122 ms
55,856 KB
testcase_11 AC 123 ms
55,776 KB
testcase_12 AC 122 ms
55,896 KB
testcase_13 AC 129 ms
55,932 KB
testcase_14 AC 133 ms
53,956 KB
testcase_15 AC 143 ms
56,132 KB
testcase_16 AC 132 ms
56,120 KB
testcase_17 AC 132 ms
56,004 KB
testcase_18 AC 133 ms
57,812 KB
testcase_19 AC 122 ms
56,036 KB
testcase_20 AC 122 ms
55,476 KB
testcase_21 AC 122 ms
56,064 KB
testcase_22 AC 123 ms
56,360 KB
testcase_23 AC 128 ms
56,312 KB
testcase_24 AC 134 ms
55,956 KB
testcase_25 AC 135 ms
57,528 KB
testcase_26 AC 133 ms
56,432 KB
testcase_27 AC 127 ms
57,756 KB
testcase_28 AC 134 ms
56,044 KB
testcase_29 AC 142 ms
55,752 KB
testcase_30 AC 143 ms
55,896 KB
testcase_31 AC 137 ms
56,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	int target(int[] A,int[] ans) {
		int p=0;
		while(p<ans.length&&(ans[p]!=-1||A[p]==-1))++p;
		if(p<ans.length)return A[p];
		else {
			for(int i=0;i<A.length;++i) {
				boolean flag=true;
				for(int j=0;j<ans.length;++j)flag&=ans[j]!=i;
				if(flag)return i;
			}
			throw new AssertionError();
		}
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[] A=new int[N];
		for(int i=0;i<N;++i) {
			A[i]=sc.nextInt();
		}
		A=Arrays.stream(A).map(i->(0<=i&&i<N)?i:-1).toArray();
		boolean ng=true;
		for(int i=0;i<N;++i)ng&=A[i]==A[0];
		ng&=0<=A[0]&&A[0]<N;
		if(ng) {
			System.out.println(-1);
			return;
		}
		int[] ans=new int[N];
		Arrays.fill(ans, -1);
		for(int i=0;i<N;++i) {
			int target=target(A, ans);//targetを誰かに塗る
			int p=0;
			while(A[p]==target||ans[p]!=-1)++p;
			ans[p]=target;
			for(int j=0;j<N;++j)if(ans[j]==-1&&A[j]==target)A[j]=-1;
		}
		for(int i=0;i<N;++i)System.out.println(ans[i]);
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}

0