結果
| 問題 |
No.335 門松宝くじ
|
| コンテスト | |
| ユーザー |
izuru_matsuura
|
| 提出日時 | 2016-02-11 22:18:45 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,077 bytes |
| コンパイル時間 | 2,483 ms |
| コンパイル使用メモリ | 244,680 KB |
| 実行使用メモリ | 334,292 KB |
| 最終ジャッジ日時 | 2024-06-12 02:51:21 |
| 合計ジャッジ時間 | 6,245 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 1 TLE * 1 -- * 8 |
ソースコード
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);
}
izuru_matsuura