結果

問題 No.282 おもりと天秤(2)
ユーザー te-shte-sh
提出日時 2017-06-08 11:42:39
言語 D
(dmd 2.106.1)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,463 bytes
コンパイル時間 3,370 ms
コンパイル使用メモリ 167,420 KB
実行使用メモリ 29,576 KB
平均クエリ数 267.08
最終ジャッジ日時 2023-09-03 14:02:02
合計ジャッジ時間 30,023 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
23,544 KB
testcase_01 AC 33 ms
23,436 KB
testcase_02 AC 28 ms
23,628 KB
testcase_03 AC 27 ms
23,820 KB
testcase_04 AC 27 ms
23,532 KB
testcase_05 AC 31 ms
24,024 KB
testcase_06 AC 33 ms
23,448 KB
testcase_07 AC 27 ms
23,820 KB
testcase_08 AC 33 ms
23,544 KB
testcase_09 AC 24 ms
23,424 KB
testcase_10 AC 455 ms
23,448 KB
testcase_11 AC 1,749 ms
28,112 KB
testcase_12 AC 941 ms
24,276 KB
testcase_13 AC 1,170 ms
28,824 KB
testcase_14 AC 1,585 ms
28,360 KB
testcase_15 AC 1,744 ms
28,352 KB
testcase_16 AC 117 ms
24,228 KB
testcase_17 AC 1,078 ms
24,288 KB
testcase_18 AC 1,472 ms
27,660 KB
testcase_19 AC 1,480 ms
29,288 KB
testcase_20 AC 1,806 ms
28,088 KB
testcase_21 AC 1,793 ms
29,576 KB
testcase_22 AC 1,816 ms
28,692 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