結果

問題 No.334 門松ゲーム
ユーザー tottoripapertottoripaper
提出日時 2018-02-18 22:08:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,594 bytes
コンパイル時間 1,566 ms
コンパイル使用メモリ 165,640 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-17 23:21:50
合計ジャッジ時間 2,620 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

int N;
int dp[1 << 12];
int K[12];

bool isKadomatsuSequence(int a, int b, int c){
    return a != b && b != c && c != a &&
        (max({a, b, c}) == b || min({a, b, c}) == b);
}

int rec(int state, int n){
    if(n == N){
        return -1;
    }
    if(dp[state] != -2){
        return dp[state];
    }

    dp[state] = -1;
    for(int i=0;i<N;++i){
        if(state >> i & 1){continue;}
        for(int j=i+1;j<N;++j){
            if(state >> j & 1){continue;}
            for(int k=j+1;k<N;++k){
                if(state >> k & 1){continue;}

                if(isKadomatsuSequence(K[i], K[j], K[k]) && rec(state | (1 << i) | (1 << j) | (1 << k), n + 3) == -1){
                        dp[state] = i + ((j + (k << 4)) << 4);
                        return dp[state];
                }
            }
        }
    }

    return dp[state];
}

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    std::cin >> N;

    for(int i=0;i<N;++i){
        std::cin >> K[i];
    }

    fill(dp, dp + (1 << 12), -2);
    
    int x = rec(0, 0);
    if(x == -1){
        std::cout << x << std::endl;
    }else{
        int a = x & 0xf, b = x >> 4 & 0xf, c = x >> 8 & 0xf;
        std::cout << a << " " << b << " " << c << std::endl;
    }
}
0