結果
| 問題 | 
                            No.334 門松ゲーム
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2016-12-17 01:06:59 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 4 ms / 2,000 ms | 
| コード長 | 1,294 bytes | 
| コンパイル時間 | 679 ms | 
| コンパイル使用メモリ | 60,640 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-30 22:14:13 | 
| 合計ジャッジ時間 | 1,392 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 13 | 
ソースコード
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;
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;
}