結果

問題 No.334 門松ゲーム
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-02-11 21:52:28
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,089 bytes
コンパイル時間 2,755 ms
コンパイル使用メモリ 196,144 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-09-02 20:29:41
合計ジャッジ時間 3,391 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.random;
import std.regex;
import std.typecons;

void main() {
    int N; scanf("%d\n", &N);
    int[] K = readln.chomp.split(" ").map!(to!int).array;

    bool kadomatsu(int a, int b, int c) {
        if (a < b && b < c) return false;
        if (c < b && b < a) return false;
        if (a == b || b == c || c == a) return false;
        return true;
    }
    
    const int INF = 1001;

    bool win(bool[] used) {
        for (int i = 0; i < N; i++) {
            if (used[i]) continue;
            for (int j = i + 1; j < N; j++) {
                if (used[j]) continue;
                for (int k = j + 1; k < N; k++) {
                    if (used[k]) continue;
                    int x = K[i],
                        y = K[j],
                        z = K[k];
                    if (kadomatsu(x, y, z)) {
                        bool[] n = used.dup;
                        n[i] = n[j] = n[k] = true;
                        bool opp = win(n);
                        if (!opp) {
                            return true;
                        }
                    }
                }
            }
        }
        return false;
    }

    bool solve() {
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                for (int k = j + 1; k < N; k++) {
                    int x = K[i],
                    y = K[j],
                    z = K[k];
                    if (kadomatsu(x, y, z)) {
                        auto used = new bool[N];
                        used[i] = used[j] = used[k] = true;
                        if (!win(used)) {
                            writefln("%(%s %)", [i, j, k]);
                            return true;
                        }
                    }
                }
            }
        }
        return false;
    }

    if (!solve()) {
        writeln(-1);
    }

}
0