結果

問題 No.241 出席番号(1)
ユーザー 184184
提出日時 2015-07-11 05:39:31
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 826 bytes
コンパイル時間 387 ms
コンパイル使用メモリ 44,188 KB
実行使用メモリ 7,096 KB
最終ジャッジ日時 2023-09-22 10:53:48
合計ジャッジ時間 4,839 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
 
int dfs(long long *b,int *ans,long long &use,int n,int m){
	if(((1LL<<n)-1)==use)return 1;
	if(n==m ){return 0;}
	 
	for(long long i=0;i<n;i++){ 
		if((b[m]&(1<<i))&&(use&(1<<i))==0){
			ans[m]=i;
			use^=1LL<<i; 
			if(dfs(b,ans,use,n,m+1))return 1;
			use^=1LL<<i;
		}
	}
	return 0;
}
int main(){
	int n;scanf("%d",&n);long long b[101]; 
	int v=0;
	int ans[101];
	long long use=0;
	for(int i=0;i<n;i++){int a;scanf("%d",&a);b[i]=((1LL<<n)-1)&~(1LL<<a);;v|=b[i];}
	dfs(b,ans,use,n,0);
	if(use==((1LL<<n)-1))for(int i=0;i<n;i++)printf("%d\n",ans[i]);
	else printf("-1\n"); 
	/*for(int i=0;i<n;i++){
		v^=b[i];
		for(int j=0;j<n;j++){
			if(v&(1<<j)){
				printf("%d\n",j);
				v^=(1<<j);
				break;
			}
		}
	}*/
		
	return 0;
}
0