結果

問題 No.241 出席番号(1)
ユーザー cielciel
提出日時 2015-07-12 03:08:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 863 bytes
コンパイル時間 974 ms
コンパイル使用メモリ 70,208 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-20 17:48:20
合計ジャッジ時間 2,761 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <random>
#include <algorithm>
#include <cstdio>
#include <unistd.h>
using namespace std;
mt19937_64 engine((unsigned int)time(NULL)^(getpid()<<16));

bool validate(const vector<int>&a,const vector<int>&r){
	vector<bool>f(r.size());
	for(int i=0;i<r.size();i++){
		if(r[i]<0 || r.size()<=r[i])return false;
		if(r[i]==a[i])return false;
		if(f[r[i]])return false;
		f[r[i]]=true;
	}
	return true;
}

int main(){
	int N;
	scanf("%d",&N);
	vector<int>a(N),r(N);
	for(int i=0;i<N;i++)scanf("%d",&a[i]),r[i]=i;
	if(0<=a[0]&&a[0]<N){
		int i=0;
		for(;i<N;i++)if(a[0]!=a[i])break;
		if(i==N){
			puts("-1");
			return 0;
		}
	}
	uniform_int_distribution<int> distribution(0, N-1);
	for(;;){
		int x=distribution(engine);
		int y=distribution(engine);
		swap(r[x],r[y]);
		if(validate(a,r))break;
	}
	for(int i=0;i<N;i++)printf("%d\n",r[i]);
}
0