結果
| 問題 |
No.100 直列あみだくじ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2014-12-11 23:43:31 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,031 bytes |
| コンパイル時間 | 1,372 ms |
| コンパイル使用メモリ | 159,240 KB |
| 実行使用メモリ | 16,952 KB |
| 最終ジャッジ日時 | 2024-06-11 20:46:33 |
| 合計ジャッジ時間 | 14,089 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | TLE * 1 -- * 44 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int(i)=0;(i)<(n);++(i))
const int MOD = 1000000007;
int N, a[51], b[51];
bool dfs(int i){
if(i == N) return true;
if(b[i] >= 0){
int j = b[i];
if(b[j] >= 0){
if(a[i] != b[j]) return false;
if(dfs(i+1)) return true;
} else {
b[j] = a[i];
if(dfs(i+1)) return true;
b[j] = -1;
}
} else {
REP(j,N){
b[i] = j;
if(b[j] >= 0){
if(a[i] != b[j]) continue;
if(dfs(i+1)) return true;
} else {
b[j] = a[i];
if(dfs(i+1)) return true;
b[j] = -1;
}
}
b[i] = -1;
}
return false;
}
int main(){
cin >> N;
REP(i,N){
cin >> a[i]; a[i]--;
b[i] = -1;
}
cout << (dfs(0)?"Yes":"No") << endl;
return 0;
}