結果
| 問題 |
No.334 門松ゲーム
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-02-11 22:04:05 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 1,609 bytes |
| コンパイル時間 | 703 ms |
| コンパイル使用メモリ | 80,720 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-22 01:00:09 |
| 合計ジャッジ時間 | 1,425 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <set>
#include <map>
#include <queue>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <cstdio>
#include <cassert>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i,m,n) for (int i = (m); (i) < (n); ++(i))
typedef long long ll;
using namespace std;
bool is_kadomatsu(int a, int b, int c) {
if (a == b or b == c or c == a) return false;
if (a < b and b < c) return false;
if (a > b and b > c) return false;
return true;
}
int main() {
int n; cin >> n;
vector<int> k(n); repeat (i,n) cin >> k[i];
vector<bool> dp(1<<n); // grundy number
repeat (s, 1<<n) {
set<int> gs;
repeat (a,n) if (s & (1<<a)) {
repeat_from (b,a+1,n) if (s & (1<<b)) {
repeat_from (c,b+1,n) if (s & (1<<c)) {
if (not is_kadomatsu(k[a], k[b], k[c])) continue;
if (not dp[s & ~ ((1<<a) | (1<<b) | (1<<c))]) {
dp[s] = true;
goto done;
}
}
}
}
done:;
}
repeat (a,n) {
repeat_from (b,a+1,n) {
repeat_from (c,b+1,n) {
if (not is_kadomatsu(k[a], k[b], k[c])) continue;
if (not dp[((1<<n)-1) & ~ ((1<<a) | (1<<b) | (1<<c))]) {
cout << a << ' ' << b << ' ' << c << endl;
return 0;
}
}
}
}
cout << -1 << endl;
return 0;
}