結果

問題 No.334 門松ゲーム
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2016-01-06 00:25:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 1,976 bytes
コンパイル時間 774 ms
コンパイル使用メモリ 91,784 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 15:25:04
合計ジャッジ時間 1,702 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))

#define MOD 1000000007

int n;
vector<int> v;
int d[30];

int isKadomatsu(int a, int b, int c){
  if((a<b&&a>c)||(a>b&&a<c)||(c<a&&c>b)||(c>a&&c<b))return 1;
  return 0;
}

int f(int d[30], int c){
  vector<int> v1;
  rep(i,0,n){
    if(d[i]==0){
      v1.pb(i);
    }
  }
  // 0
  if(c == 0){
    int ret = 1;
    rep(i,0,v1.sz){
      rep(j,i+1,v1.sz){
        rep(k,j+1,v1.sz){
          if(1==isKadomatsu(v[v1[i]],v[v1[j]],v[v1[k]])){
            d[v1[i]]=1;d[v1[j]]=1;d[v1[k]]=1;
            ret &= f(d,1-c);
            d[v1[i]]=0;d[v1[j]]=0;d[v1[k]]=0;
          }
        }
      }
    }
    return ret;
  }
  // 1
  else{
    int ret = 0;
    rep(i,0,v1.sz){
      rep(j,i+1,v1.sz){
        rep(k,j+1,v1.sz){
          if(1==isKadomatsu(v[v1[i]],v[v1[j]],v[v1[k]])){
            d[v1[i]]=1;d[v1[j]]=1;d[v1[k]]=1;
            ret |= f(d,1-c);
            d[v1[i]]=0;d[v1[j]]=0;d[v1[k]]=0;
          }
        }
      }
    }
    return ret;
  }
}

int main(){
  cin>>n;
  rep(i,0,n){
    int a;
    cin>>a;
    v.pb(a);
  }
  clr(d,0);
  rep(a,0,n){
    rep(b,a+1,n){
      rep(c,b+1,n){
        if(1==isKadomatsu(v[a],v[b],v[c])){
          d[a]=1;d[b]=1;d[c]=1;
          if(0==f(d,1)){
            cout << a << " " << b << " " << c << endl;
            return 0;
          }
          d[a]=0;d[b]=0;d[c]=0;
        }
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
0