結果

問題 No.334 門松ゲーム
ユーザー nenuonnenuon
提出日時 2017-07-01 14:19:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,575 bytes
コンパイル時間 879 ms
コンパイル使用メモリ 95,316 KB
実行使用メモリ 814,720 KB
最終ジャッジ日時 2024-04-15 09:59:45
合計ジャッジ時間 4,674 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
typedef long long ll;
int n;
int a[12];

bool reg[1<<12];
tuple<int, int, int> dp[1<<12];
const int inf = 1e9;

bool kadomatsu(int x, int y, int z) {
  if(x == y || y == z || z == x) return false;
  if(x > y && y < z) return true;
  if(x < y && y > z) return true;
  return false;
}

// sは集合
tuple<int, int, int> f(int s) {
  if(reg[s]) return dp[s]; // 調査済み

  tuple<int, int, int> ret {inf, inf, inf};
  FOR(i,0,n) FOR(j,i+1,n) FOR(k,j+1,n) {
    if (s & (1 << i)) continue; // 調査済み
    if (s & (1 << j)) continue;
    if (s & (1 << k)) continue;
    if (kadomatsu(a[i], a[j], a[k])) {
      auto val = f(s | (1 << i) | (1 << j) || (1 << k));
      if (get<0>(val) == inf) {
        chmin(ret, make_tuple(i, j, k));
      }
    }
  }
  dp[s] = ret;
  reg[s] = true;
  return ret;
}

int main(){
  FOR(i,0,1<<12) reg[i] = false;
  cin >> n;
  FOR(i,0,n) cin >> a[i];
  auto ans = f(0);
  if(get<0>(ans) == inf) {
    cout << -1 << endl;
  } else {
    int x, y, z;
    tie(x, y, z) = ans;
    printf("%d %d %d\n",x,y,z);
  }
  return 0;
}
0