結果

問題 No.334 門松ゲーム
ユーザー なおなお
提出日時 2016-01-26 16:55:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,228 bytes
コンパイル時間 1,347 ms
コンパイル使用メモリ 163,664 KB
実行使用メモリ 4,684 KB
最終ジャッジ日時 2023-10-21 16:22:16
合計ジャッジ時間 2,406 ms
ジャッジサーバーID
(参考情報)
judge9 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, f, t) for(int(i)=(f);(i)<(t);++(i))
#define REP(i, n) FOR(i, 0, n)
#define EACH(it, c) for(auto it=(c).begin();it!=(c).end();++it)

bool isKadomatsuSequence(int a, int b, int c){
    if(a == b || a == c || b == c) return false;
    if(b == max(max(a,c),b) || b == min(min(a,c),b)) return true;
    return false;
}

int N,K[20];
char memo[1<<20];
vector<array<int,3> >v;

int dfs(int bit, int plr, int &a, int &b, int &c){
    if(memo[bit] != -1) return !!memo[bit];
    int res = 0;
    EACH(it,v){
        int i = it->at(0), j = it->at(1), k = it->at(2);
        int msk = 1<<i|1<<j|1<<k;
        if(bit & msk) continue;
        if(!dfs(bit|msk, 1-plr, a, b, c)){
            a = i, b = j, c = k, res = 1; break;
        }
    }
    return (memo[bit] = res);
}

int main(){
    cin >> N;
    REP(i,N) cin >> K[i];
    memset(memo, -1, sizeof(memo));

    REP(i,N-2)FOR(j,i+1,N-1)FOR(k,j+1,N){
        if(isKadomatsuSequence(K[i],K[j],K[k])){
            array<int,3> ar = {i,j,k};
            v.push_back(ar);
        }
    }

    int i,j,k;
    if(dfs(0,0,i,j,k)){
        cout << i << " " << j << " " << k << endl;
    } else {
        cout << -1 << endl;
    }
}
0