結果

問題 No.334 門松ゲーム
ユーザー rapurasurapurasu
提出日時 2016-09-05 17:46:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 2,325 bytes
コンパイル時間 1,152 ms
コンパイル使用メモリ 158,956 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-27 16:41:00
合計ジャッジ時間 1,795 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

 #include<bits/stdc++.h>
 using namespace std;
#define INF 1000000000
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
int N;
int K[13];
bool dp[1<<14];
//消すことが可能か
bool check(long long x){
     REP(i,N){
         REP(j,i){
             REP(k,j){
                 if(!(x>>i&1)){
                    if(!(x>>j&1)){
                       if(!(x>>k&1)){
                          if((K[i]<K[j]&&K[j]>K[k])||(K[i]>K[j]&&K[j]<K[k])){
                              return true;
                          }
                       }
                    }
                 }
             }
         }
     }
     return false;
}

void bit_dp(){
     long long x=(1<<N)-1;
     int a=-1;
     int b=-1;
     int c=-1;
     dp[x]=false;
     for(long long i=x-1;i>=0;i--){
         if(check(i)==false){
            dp[i]=false;
         }else{
            dp[i]=false;
            for(int l=0;l<N;l++){
                for(int j=l+1;j<N;j++){
                    for(int k=j+1;k<N;k++){

                       if(!((i>>l)&1)){
                          if(!((i>>j)&1)){
                             if(!((i>>k)&1)){
                                long long y=i;
                                y=y|(1<<l);
                                y=y|(1<<j);
                                y=y|(1<<k);
                                if((dp[y]==false)&&((K[l]<K[j]&&K[j]>K[k])||(K[l]>K[j]&&K[j]<K[k]))){
                                   dp[i]=true;
                                   if(i==0){
                                      if(a==-1){
                                         a=l;
                                         b=j;
                                         c=k;
                                         //cout<<i<<"a"<<y<<endl;
                                      }
                                   }
                                }
                                
                                //dp[i]=true;
                             }
                          }
                       }
                    }
                }
            }
            
         }
         //cout<<i<<" "<<dp[i]<<endl;
     }
     if(a==-1){
        cout<<-1<<endl;
     }else{
        cout<<a<<" "<<b<<" "<<c<<endl;
     }
}

int main(){
    cin>>N;
    REP(i,N){
       cin>>K[i];
    }
    bit_dp();
}
0