結果

問題 No.334 門松ゲーム
ユーザー koba-e964koba-e964
提出日時 2016-12-17 01:06:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,294 bytes
コンパイル時間 508 ms
コンパイル使用メモリ 63,652 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-20 18:29:04
合計ジャッジ時間 1,959 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 4 ms
4,380 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0