結果

問題 No.241 出席番号(1)
ユーザー ぴろずぴろず
提出日時 2015-07-10 22:47:00
言語 Java19
(openjdk 21)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 748 bytes
コンパイル時間 2,197 ms
コンパイル使用メモリ 73,940 KB
実行使用メモリ 55,936 KB
最終ジャッジ日時 2023-08-20 17:44:00
合計ジャッジ時間 8,323 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
55,448 KB
testcase_01 AC 127 ms
55,748 KB
testcase_02 AC 128 ms
55,688 KB
testcase_03 AC 126 ms
55,808 KB
testcase_04 AC 132 ms
55,456 KB
testcase_05 AC 125 ms
55,860 KB
testcase_06 AC 127 ms
55,480 KB
testcase_07 AC 126 ms
55,400 KB
testcase_08 AC 125 ms
55,264 KB
testcase_09 AC 125 ms
53,976 KB
testcase_10 AC 126 ms
55,480 KB
testcase_11 AC 124 ms
55,700 KB
testcase_12 AC 126 ms
55,704 KB
testcase_13 AC 130 ms
55,700 KB
testcase_14 AC 136 ms
55,848 KB
testcase_15 AC 136 ms
55,776 KB
testcase_16 AC 125 ms
55,552 KB
testcase_17 AC 127 ms
55,936 KB
testcase_18 AC 126 ms
55,900 KB
testcase_19 AC 126 ms
55,772 KB
testcase_20 AC 125 ms
55,632 KB
testcase_21 AC 126 ms
55,600 KB
testcase_22 AC 127 ms
55,744 KB
testcase_23 AC 132 ms
55,408 KB
testcase_24 AC 136 ms
55,772 KB
testcase_25 AC 137 ms
55,640 KB
testcase_26 AC 138 ms
55,488 KB
testcase_27 AC 133 ms
55,472 KB
testcase_28 AC 136 ms
55,564 KB
testcase_29 AC 138 ms
55,336 KB
testcase_30 AC 138 ms
55,828 KB
testcase_31 AC 137 ms
55,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no241;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		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();
		}
		int[] id = new int[n];
		for(int i=0;i<n;i++) {
			id[i] = i;
		}
		for(int i=0;i<n;i++) {
			if (a[i] != id[i]) {
				continue;
			}
			boolean flag = false;
			for(int j=0;j<n;j++) {
				if (i == j) {
					continue;
				}
				if (a[i] != id[j] && a[j] != id[i]) {
					int temp = id[i];
					id[i] = id[j];
					id[j] = temp;
					flag = true;
					break;
				}
			}
			if (!flag) {
				System.out.println(-1);
				return;
			}
		}
		for(int i=0;i<n;i++) {
			System.out.println(id[i]);
		}
	}


}
0