結果
問題 | No.100 直列あみだくじ |
ユーザー |
|
提出日時 | 2017-01-05 18:01:58 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,463 bytes |
コンパイル時間 | 801 ms |
コンパイル使用メモリ | 77,512 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-12-16 10:17:40 |
合計ジャッジ時間 | 93,237 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 WA * 5 |
ソースコード
#include <iostream>#include <vector>#include <functional>#include <sys/signal.h>#include <sys/time.h>#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))using namespace std;void handler(int) {cout << "No" << endl;exit(EXIT_SUCCESS);}int main() {// timersignal(SIGALRM, handler);itimerval tv;tv.it_value.tv_sec = 4;tv.it_value.tv_usec = 800 * 1000;tv.it_interval = {};setitimer(ITIMER_REAL, &tv, NULL);// solveint n; cin >> n;vector<int> f(n); repeat (i,n) { cin >> f[i]; -- f[i]; }vector<int> g(n, -1);vector<bool> used(n);function<bool (int)> go = [&](int i) {if (i == n) return true;if (g[i] == -1) {repeat (j,n) if (not used[j]) {used[j] = true;g[i] = j;if (go(i)) return true;g[i] = -1;used[j] = false;}} else {if (g[g[i]] == -1) {if (not used[f[i]]) {used[f[i]] = true;g[g[i]] = f[i];if (go(i+1)) return true;g[g[i]] = -1;used[f[i]] = false;}} else {if (g[g[i]] == f[i]) {if (go(i+1)) return true;}}}return false;};cout << (go(0) ? "Yes" : "No") << endl;return 0;}