結果

問題 No.334 門松ゲーム
ユーザー nebukuro09nebukuro09
提出日時 2016-11-16 20:53:57
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 984 bytes
コンパイル時間 914 ms
コンパイル使用メモリ 99,780 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-09-02 22:55:39
合計ジャッジ時間 1,962 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import std.stdio;
import std.array;
import std.string;
import std.conv;
import std.algorithm;
import std.typecons;
import std.range;
import std.random;
import std.math;
import std.container;

bool isKadomatsu(int a, int b, int c) {
  return ((a > b && b < c && a != c) || (a < b && b > c && a != c));
}

bool rec(int[] A) {
  if (A.length < 3)
    return false;

  bool[] results;
  foreach (i; 0..A.length)
    foreach (j; (i+1)..A.length)
      foreach (k; (j+1)..A.length) {
	if (isKadomatsu(A[i], A[j], A[k]))
	  results ~= rec(A[0..i] ~ A[i+1..j] ~ A[j+1..k] ~ A[k+1..$]);
	else
	  results ~= true;
      }
  return !all(results);
}

void main() {
  auto N = readln.chomp.to!int;
  auto A = readln.split.map!(to!int).array;

  foreach (i; 0..A.length)
    foreach (j; (i+1)..A.length)
      foreach (k; (j+1)..A.length)
	if (isKadomatsu(A[i], A[j], A[k]) &&
	    !rec(A[0..i] ~ A[i+1..j] ~ A[j+1..k] ~ A[k+1..$])) {
	  writeln(i, " ", j, " ", k);
	  return;
	}

  writeln(-1);
}
0