結果

問題 No.334 門松ゲーム
ユーザー motimoti
提出日時 2016-01-16 00:29:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 1,947 bytes
コンパイル時間 1,019 ms
コンパイル使用メモリ 114,320 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 23:50:24
合計ジャッジ時間 1,946 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int N;
int A[15];

bool kadomatsu(int a, int b, int c) {
  if(!(A[a] != A[b] && A[b] != A[c] && A[c] != A[a])) { return false; }
  if(A[b] < A[a] && A[b] < A[c]) { return true; }
  if(A[b] > A[a] && A[b] > A[c]) { return true; }
  return false;
}

bool dfs(set<int>& used) {

  bool win = 0;
  rep(i, N) REP(j, i+1, N) REP(k, j+1, N) {
    if(used.count(i) || used.count(j) || used.count(k)) { continue; }
    if(kadomatsu(i, j, k)) {
      used.insert(i);
      used.insert(j);
      used.insert(k);
      win = win || !dfs(used);
      used.erase(i);
      used.erase(j);
      used.erase(k);
    }
  }

  return win;
}

int main() {

  cin >> N;
  rep(i, N) {
    cin >> A[i];
  }

  vector<int> res = {inf, inf, inf};
  bool win = 0;
  rep(i, N) REP(j, i+1, N) REP(k, j+1, N) {
    if(kadomatsu(i, j, k)) {
      set<int> used;
      used.insert(i);
      used.insert(j);
      used.insert(k);
      if(!dfs(used)) {
        win = 1;
        res = min(res, {i, j, k});
      }
    }
  }

  if(win) {
    cout << res[0] << " " << res[1] << " " << res[2] << endl;
  }
  else {
    cout << "-1\n";
  }

  return 0;
}
0