結果

問題 No.334 門松ゲーム
ユーザー kimiyukikimiyuki
提出日時 2016-02-11 22:04:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,609 bytes
コンパイル時間 745 ms
コンパイル使用メモリ 81,036 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 23:31:36
合計ジャッジ時間 1,699 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <set>
#include <map>
#include <queue>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <cstdio>
#include <cassert>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i,m,n) for (int i = (m); (i) < (n); ++(i))
typedef long long ll;
using namespace std;
bool is_kadomatsu(int a, int b, int c) {
    if (a == b or b == c or c == a) return false;
    if (a < b and b < c) return false;
    if (a > b and b > c) return false;
    return true;
}
int main() {
    int n; cin >> n;
    vector<int> k(n); repeat (i,n) cin >> k[i];
    vector<bool> dp(1<<n); // grundy number
    repeat (s, 1<<n) {
        set<int> gs;
        repeat (a,n) if (s & (1<<a)) {
            repeat_from (b,a+1,n) if (s & (1<<b)) {
                repeat_from (c,b+1,n) if (s & (1<<c)) {
                    if (not is_kadomatsu(k[a], k[b], k[c])) continue;
                    if (not dp[s & ~ ((1<<a) | (1<<b) | (1<<c))]) {
                        dp[s] = true;
                        goto done;
                    }
                }
            }
        }
done:;
    }
    repeat (a,n) {
        repeat_from (b,a+1,n) {
            repeat_from (c,b+1,n) {
                if (not is_kadomatsu(k[a], k[b], k[c])) continue;
                if (not dp[((1<<n)-1) & ~ ((1<<a) | (1<<b) | (1<<c))]) {
                    cout << a << ' ' << b << ' ' << c << endl;
                    return 0;
                }
            }
        }
    }
    cout << -1 << endl;
    return 0;
}
0