結果

問題 No.335 門松宝くじ
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-02-11 22:18:45
言語 D
(dmd 2.106.1)
結果
TLE  
実行時間 -
コード長 2,077 bytes
コンパイル時間 3,164 ms
コンパイル使用メモリ 242,636 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-09-02 20:30:11
合計ジャッジ時間 6,854 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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, M; scanf("%d %d\n", &N, &M);
    auto E = new int[][M];
    foreach (i; 0 .. M) {
        E[i] = 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;
    }
 
    auto T = new RedBlackTree!(Tuple!(int, int, int))[M];
    foreach (i; 0 .. M) {
        T[i] = new RedBlackTree!(Tuple!(int, int, int));
    }

    for (int p = 0; p < M; p++) {
        const int[] X = E[p];
        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 = X[i], y = X[j], z = X[k];
                    if (kadomatsu(x, y, z)) {
                        T[p].insert(tuple(x, y, z));
                    }
                }
            }
        }
    }

    auto Z = new int[M];
    for (int x = 1; x <= N; x++) {
        for (int y = 1; y <= N; y++) {
            if (x == y) continue;
            foreach (p; 0 .. M) {
                int m = 0;
                for (int z = 1; z <= N; z++) {
                    if (x == z || y == z) continue;

                    auto r = [x, y, z];
                    sort(r);
                    do {
                        auto t = tuple(r[0], r[1], r[2]);
                        if (t in T[p]) {
                            m = max(m, x, y, z);
                        }
                    } while (nextPermutation(r));
                }
                Z[p] += m;
            }
        }
    }

    int s = -1, index = -1;
    foreach (int i; 0 .. M) {
        if (s < Z[i]) {
            s = Z[i];
            index = i;
        }
    }
    writeln(index);

}
0