結果

問題 No.334 門松ゲーム
ユーザー btkbtk
提出日時 2016-01-16 00:04:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,290 bytes
コンパイル時間 1,702 ms
コンパイル使用メモリ 172,648 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 23:44:55
合計ジャッジ時間 2,231 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef vector<int> V;

V K;
map<V,bool> memo;
using namespace std;

bool solve(V& now){
    if(memo.count(now))return memo[now];
    int n=now.size();
    bool win=false;
    for(int a = 0; a < n; a++){
        if(now[a]<0)continue;
        for(int b=a+1; b <n; b++){
            if(now[b]<0)continue;
            for(int c=b+1; c <n; c++){
                if(now[c]<0||now[a]==now[c])continue;

                if((now[a]>now[b]&&now[c]>now[b])||(now[a]<now[b]&&now[c]<now[b])){
                    V m=now;
                    m[a]=m[b]=m[c]=-1;
                    if(solve(m)==false)win=true;
                }
            }
        }
    }
    return memo[now]=win;
}
int main() {
    int N;cin>>N;
    K.resize(N);
    for(auto& it : K)cin>>it;

    for(int a = 0; a < N; a++){
        for(int b=a+1; b <N; b++){
            for(int c=b+1; c <N; c++){
                if(K[a]!=K[c]&&((K[a]>K[b]&&K[c]>K[b])||(K[a]<K[b]&&K[c]<K[b]))){
                    V m=K;
                    m[a]=m[b]=m[c]=-1;
                    if(solve(m)==false){
                        cout<<a<<" "<<b<<" "<<c<<endl;
                        return 0;
                    }
                }
            }
        }
    }
    cout<<-1<<endl;
    return 0;
}
0