結果

問題 No.241 出席番号(1)
ユーザー 37zigen37zigen
提出日時 2020-03-30 03:48:21
言語 Java21
(openjdk 21)
結果
AC  
実行時間 132 ms / 2,000 ms
コード長 1,165 bytes
コンパイル時間 3,577 ms
コンパイル使用メモリ 73,880 KB
実行使用メモリ 56,712 KB
最終ジャッジ日時 2023-08-30 20:15:31
合計ジャッジ時間 9,036 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
56,116 KB
testcase_01 AC 122 ms
56,392 KB
testcase_02 AC 126 ms
55,820 KB
testcase_03 AC 120 ms
55,832 KB
testcase_04 AC 126 ms
56,192 KB
testcase_05 AC 120 ms
55,880 KB
testcase_06 AC 120 ms
55,936 KB
testcase_07 AC 119 ms
55,596 KB
testcase_08 AC 119 ms
55,840 KB
testcase_09 AC 120 ms
56,628 KB
testcase_10 AC 119 ms
55,888 KB
testcase_11 AC 119 ms
56,360 KB
testcase_12 AC 119 ms
55,760 KB
testcase_13 AC 121 ms
55,800 KB
testcase_14 AC 128 ms
56,004 KB
testcase_15 AC 128 ms
56,564 KB
testcase_16 AC 118 ms
55,924 KB
testcase_17 AC 117 ms
56,176 KB
testcase_18 AC 119 ms
56,092 KB
testcase_19 AC 118 ms
56,204 KB
testcase_20 AC 118 ms
55,836 KB
testcase_21 AC 124 ms
56,152 KB
testcase_22 AC 119 ms
55,820 KB
testcase_23 AC 125 ms
55,812 KB
testcase_24 AC 131 ms
56,296 KB
testcase_25 AC 132 ms
55,896 KB
testcase_26 AC 129 ms
56,536 KB
testcase_27 AC 125 ms
56,068 KB
testcase_28 AC 130 ms
56,132 KB
testcase_29 AC 128 ms
56,532 KB
testcase_30 AC 130 ms
55,944 KB
testcase_31 AC 131 ms
56,712 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();
			if(!(0<=A[i]&&A[i]<N))A[i]=-1;
		}
		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