結果

問題 No.355 数当てゲーム(2)
ユーザー te-sh
提出日時 2017-07-11 14:09:03
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 955 bytes
コンパイル時間 775 ms
コンパイル使用メモリ 115,792 KB
実行使用メモリ 25,464 KB
平均クエリ数 20.67
最終ジャッジ日時 2024-06-12 20:51:33
合計ジャッジ時間 5,098 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 52
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;

struct Res { int x, y; }

void main()
{
  auto d = new bool[](10);
  auto s = new int[](10);

  foreach (i; 3..10) {
    auto r = ask([0,1,2,i]);
    s[i] = r.x + r.y;
  }

  auto rm1 = s[3..10].maxElement;
  foreach (i; 3..10)
    if (s[i] == rm1)
      d[i] = true;

  if (d[3..10].count(true) == 1)
    d[0..3][] = true;

  if (d.count(true) < 4) {
    foreach (i; 0..3) {
      auto r = ask([3,4,5,i]);
      s[i] = r.x + r.y;
    }
    auto rm2 = s[0..3].maxElement;
    foreach (i; 0..3)
      if (s[i] == rm2)
        d[i] = true;
  }

  auto t = d.enumerate.filter!"a[1]".map!"a[0]".array.to!(int[]);

  do {
    ask(t);
  } while (t.nextPermutation);
}

auto ask(int[] n)
{
  import core.stdc.stdlib;
  writeln(n.to!(string[]).join(" "));
  stdout.flush();
  auto rd = readln.split.to!(int[]), x = rd[0], y = rd[1];
  if (x == 4 && y == 0) exit(0);
  return Res(rd[0], rd[1]);
}
0