結果
| 問題 |
No.334 門松ゲーム
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-12-17 01:07:35 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 1,130 bytes |
| コンパイル時間 | 449 ms |
| コンパイル使用メモリ | 57,296 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-30 22:14:19 |
| 合計ジャッジ時間 | 1,118 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 |
ソースコード
#include <cassert>
#include <iostream>
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
using namespace std;
const int N = 12;
int n;
int a[N];
int dp[1 << N];
bool is_kadomatsu(int x, int y, int z) {
if (a[x] != a[y] && a[y] != a[z] && a[z] != a[x]) {
return (a[x] < a[y] && a[y] > a[z])
|| (a[x] > a[y] && a[y] < a[z]);
}
return false;
}
int main(void){
cin >> n;
REP(i, 0, n) {
cin >> a[i];
}
REP(bits, 0, 1 << n) {
int all_stuck = true;
REP(i, 0, n) {
if ((bits & (1 << i)) == 0) { continue; }
REP(j, i + 1, n) {
if ((bits & (1 << j)) == 0) { continue; }
REP(k, j + 1, n) {
if ((bits & (1 << k)) == 0) { continue; }
if (is_kadomatsu(i, j, k)) {
all_stuck &= dp[bits ^ 1 << i ^ 1 << j ^ 1 << k];
}
}
}
}
dp[bits] = not all_stuck;
}
if (dp[(1 << n) - 1]) {
REP(i, 0, n) {
REP(j, i + 1, n) {
REP(k, j + 1, n) {
if (is_kadomatsu(i, j, k) && dp[((1 << n) - 1) ^ 1 << i ^ 1 << j ^ 1 << k] == 0) {
cout << i << " " << j << " " << k << endl;
return 0;
}
}
}
}
assert (0);
}
cout << -1 << endl;
}