結果

問題 No.334 門松ゲーム
ユーザー rickythetarickytheta
提出日時 2016-01-15 22:45:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,459 bytes
コンパイル時間 1,371 ms
コンパイル使用メモリ 165,068 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 23:25:18
合計ジャッジ時間 2,065 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

string res = "zzz";

int dfs(vi rest,int turn){
  if(rest.size()<3)return (turn+1)%2;
  int n = rest.size();
  int pl = turn%2;
  bool fl = false;
  REP(i,n)REP(j,i)REP(k,j){
    int a = rest[k];
    int b = rest[j];
    int c = rest[i];
    if((a<b && c<b) || (a>b && c>b)){
      // ok
      vi next = rest;
      next.erase(next.begin()+i);
      next.erase(next.begin()+j);
      next.erase(next.begin()+k);
      bool r = dfs(next,turn+1)==pl;
      if(r){
        fl = true;
        if(turn != 0)return pl;
        string t = "";
        t += (char)(k+'a');
        t += (char)(j+'a');
        t += (char)(i+'a');
        res = min(res,t);
      }
    }
  }
  if(fl)return pl;
  else return (pl+1)%2;
}

int main(){
  int n;
  cin>>n;
  vi k(n);
  REP(i,n)cin>>k[i];
  dfs(k,0);
  if(res == "zzz"){
    cout<<-1<<endl;
  }else{
    cout << res[0]-'a' << " " << res[1]-'a' << " " << res[2]-'a' << endl;
  }
  return 0;
}
0