結果

問題 No.334 門松ゲーム
ユーザー face4face4
提出日時 2018-08-15 19:10:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,048 bytes
コンパイル時間 594 ms
コンパイル使用メモリ 65,224 KB
実行使用メモリ 814,720 KB
最終ジャッジ日時 2023-10-24 17:29:13
合計ジャッジ時間 3,716 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
using namespace std;

int n;
int ansi = -1, ansj = -1, ansk = -1;
int a[20];

bool dfs(int bitmask){
    for(int i = 0; i < n-2; i++){
        for(int j = i+1; j < n-1; j++){
            for(int k = j+1; k < n; k++){
                // bitmask状況下においてi, j, kを選択できる
                bool x = ~bitmask&(1<<i) && ~bitmask&(1<<j) && ~bitmask&(1<<k);
                // i, j, kが門松列を成す
                bool y = (a[i]-a[j])*(a[k]-a[j]) > 0;
                // 必勝
                bool z = !dfs(bitmask | (1<<i) | (1<<j) | (1<<k));
                if(x && y && z){
                    ansi = i, ansj = j, ansk = k;
                    return true;
                }
            }
        }
    }

    // bitmask状況下において新しく門松列を作ることが出来ない
    return false;
}

int main(){
    cin >> n;

    for(int i = 0; i < n; i++)  cin >> a[i];

    if(dfs(0))  cout << ansi << " " << ansj << " " << ansk << endl;
    else        cout << -1 << endl;

    return 0;
}
0