結果

問題 No.282 おもりと天秤(2)
ユーザー te-shte-sh
提出日時 2018-01-09 17:27:17
言語 D
(dmd 2.106.1)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,463 bytes
コンパイル時間 3,262 ms
コンパイル使用メモリ 166,220 KB
実行使用メモリ 46,212 KB
平均クエリ数 267.08
最終ジャッジ日時 2023-09-03 17:57:17
合計ジャッジ時間 28,855 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
23,556 KB
testcase_01 AC 30 ms
23,436 KB
testcase_02 AC 24 ms
23,364 KB
testcase_03 AC 24 ms
24,288 KB
testcase_04 AC 23 ms
24,276 KB
testcase_05 AC 27 ms
24,060 KB
testcase_06 AC 27 ms
23,664 KB
testcase_07 AC 23 ms
23,484 KB
testcase_08 AC 27 ms
23,772 KB
testcase_09 AC 19 ms
24,264 KB
testcase_10 AC 436 ms
23,568 KB
testcase_11 AC 1,590 ms
29,428 KB
testcase_12 AC 860 ms
23,688 KB
testcase_13 AC 1,073 ms
29,072 KB
testcase_14 AC 1,345 ms
27,800 KB
testcase_15 AC 1,569 ms
28,652 KB
testcase_16 AC 98 ms
24,264 KB
testcase_17 AC 1,018 ms
23,964 KB
testcase_18 AC 1,375 ms
27,936 KB
testcase_19 AC 1,315 ms
27,528 KB
testcase_20 AC 1,617 ms
27,884 KB
testcase_21 AC 1,628 ms
29,228 KB
testcase_22 AC 1,620 ms
12,900 KB
testcase_23 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

void main()
{
  auto n = readln.chomp.to!int;
  auto q = (n - 1).bsr + 1, p = (1 << q), r = 0;

  auto gi = new int[][](n, n);

  auto ask(int[][] pairs)
  {
    auto send = pairs.chain([-1, -1].repeat).take(n);
    writeln("? ", send.joiner.map!"a+1".array.to!(string[]).join(" "));
    stdout.flush();

    auto ci = readln.split;
    foreach (pair, c; lockstep(pairs, ci.take(pairs.length))) {
      auto d = c.predSwitch(">", 1, "=", 0, "<", -1);
      if (pair[0] != -1 && pair[1] != -1) {
        gi[pair[0]][pair[1]] = d;
        gi[pair[1]][pair[0]] = -d;
      }
    }
  }

  foreach (i; 1..q+1) {
    auto bs = (1 << (i - 1)), bs2 = (bs << 1);
    foreach (j; 0..bs) {
      int[][] pairs;
      foreach (k; 0..p/bs2) {
        foreach (m; 0..bs) {
          auto pair = [k * bs2 + m, k * bs2 + bs + (m + j) % bs];
          if (pair[0] < n && pair[1] < n) {
            gi[pair[0]][pair[1]] = 1;
            pairs ~= pair;
          } else {
            pairs ~= [-1, -1];
          }
        }
      }
      ask(pairs);
    }
  }

  auto ri = n.iota.array;
  ri.sort!((a, b) => gi[a][b] < 0);

  writeln("! ", ri.map!"a+1".array.to!(string[]).join(" "));
}

pragma(inline) {
  import core.bitop;
  pure int bsf(T)(T n) { return core.bitop.bsf(ulong(n)); }
  pure int bsr(T)(T n) { return core.bitop.bsr(ulong(n)); }
  pure int popcnt(T)(T n) { return core.bitop.popcnt(ulong(n)); }
}
0