結果

問題 No.334 門松ゲーム
ユーザー nanophoto12nanophoto12
提出日時 2016-01-17 10:34:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 2,296 bytes
コンパイル時間 690 ms
コンパイル使用メモリ 77,676 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 00:27:49
合計ジャッジ時間 1,508 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
#include <sstream>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <climits>
using namespace std;

typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)

bool ok(int x, int y, int z){
    bool ret=true;
    if(x==y || x==z || y==z) ret=false;
    else{
        if(x<y && y<z) ret=false;
        if(x>y && y>z) ret=false;
    }
    return ret;
}

int main(int argc, char const *argv[]) {
    int n;
    int k[12];
    
    cin >>n;
    REP(i,n) cin >>k[i];
    
    vector<bool> w((1 << n) + 1);
    w[0]=false;
    
    FOR(state,1,1<<n)
    {
        int ones=0;
        REP(i,n) ones+=(state>>i)&1;
        
        if(ones<3){
            w[state]=false;
        }
        else{
            w[state]=false;
            FOR(a,0,n)FOR(b,a+1,n)FOR(c,b+1,n){
                if((state>>a)&1 && (state>>b)&1 && (state>>c)&1){
                    if(ok(k[a],k[b],k[c]))
                    {
                        int nx=state-(1<<a)-(1<<b)-(1<<c);
                        
                        if(!w[nx]){
                            w[state]=true;
                            break;
                        }
                    }
                    
                }
            }
        }
    }
    
    if(!w[(1<<n)-1]) printf("-1\n");
    else{
        //勝てる方法があるので小さい方から試して見つかったら終わり
        
        int aa = 0,bb = 0,cc = 0;
        bool find=false;
        FOR(a,0,n){
            FOR(b,a+1,n){
                FOR(c,b+1,n){
                    if(ok(k[a],k[b],k[c])){ //門松数?
                        if(!w[(1<<n)-1-(1<<a)-(1<<b)-(1<<c)]){
                            aa=a;
                            bb=b;
                            cc=c;
                            find=true;
                            break;
                        }
                    }
                }
                if(find) break;
            }
            if(find) break;
        }
        
        cout << aa << " " << bb << " " << cc << endl;
    }
    
    return 0;
}
0