結果

問題 No.241 出席番号(1)
ユーザー IL_mstaIL_msta
提出日時 2015-07-12 02:29:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,186 bytes
コンパイル時間 1,407 ms
コンパイル使用メモリ 90,812 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-20 17:48:17
合計ジャッジ時間 2,471 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES
 
#include <iostream>
#include <iomanip>
 
#include <algorithm>
#include <cmath>
 
#include <string>
//#include <array>
#include <list>
#include <queue>
#include <vector>
#include <complex>
#include <set>
#include <map>
 
/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
 
#define PII pair<int,int>
/////////
typedef long long LL;
typedef long double LD;
/////////
using namespace::std;
/////////
 
int main(void){
    std::cin.tie(0); 
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed;//
    //cout << setprecision(6);//

    int N;
	cin>>N;
	int A[50];
	int U[50];
	int Umax = 0;
	int UmaxNo = -1;
	rep(i,50)U[i]=0;
	rep(i,N){
		cin>>A[i];
		++U[ A[i] ];
		if( A[i] >= N){
			A[i] = -1;
		}
		else if(Umax < U[ A[i] ] ){
			Umax = U[ A[i] ];
			UmaxNo = A[i];
		}
	}
	rep(i,N){
		if(U[i] == N){
			P(-1);
			return 0;
		}
	}
	vector<int> No;
	if( Umax > N/2){
		rep(i,N){
			if(A[i] != UmaxNo){
				//iにUmaxNo
				int pipo=0;
				rep(j,i){
					if(j==UmaxNo)pipo=1;
					No.push_back(j+pipo);
				}
				No.push_back(UmaxNo);
				pipo=1;
				for(int j=i+1;j<N;++j){
					if(j>UmaxNo)pipo=0;
					No.push_back(j-pipo);
				}
				break;
			}
		}
	}else{
		rep(i,N){
			No.push_back(i);
		}
	}
	int num;
	bool use[50];
	bool make;
	do{
		make = false;
		/*rep(i,N){
			cout << No[i] << " ";
		}
		cout << endl;
		*/
		num = -1;
		rep(i,N){
			if(A[i] == No[i]){
				num = i;
				break;
			}
		}
		if(num == -1){
			break;
		}
		
		for(;;)
		{
			if(No[num] < N-1){
				rep(i,N) use[i] = false;
				++No[num];
				rep(i,num){
					use[ No[i] ] = true;
				}
				while( No[num] < N && use[ No[num] ] == true)
				{++No[num];}
						
				if( No[num] < N){
					use[ No[num] ] = true;
					for(int i = num+1;i<N;++i){
						rep(j,N){
							if(use[j] == false){
								No[i] = j;
								use[j] = true;
								break;
							}
						}
					}
					make = true;
					break;
				}
			}
			
			if( No[num] >= N-1){
				--num;
				if(num < 0){
					P(-1);
					return 0;
				}
			}
		}
	}while( make==true || next_permutation(No.begin(),No.end()) );
	rep(i,N)P(No[i]);
    return 0;
}
0