結果

問題 No.282 おもりと天秤(2)
ユーザー te-shte-sh
提出日時 2018-01-09 17:31:21
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 1,647 ms / 5,000 ms
コード長 1,517 bytes
コンパイル時間 3,544 ms
コンパイル使用メモリ 169,308 KB
実行使用メモリ 29,572 KB
平均クエリ数 267.12
最終ジャッジ日時 2023-09-03 17:57:57
合計ジャッジ時間 21,528 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
24,204 KB
testcase_01 AC 26 ms
23,304 KB
testcase_02 AC 23 ms
23,988 KB
testcase_03 AC 25 ms
23,568 KB
testcase_04 AC 23 ms
23,304 KB
testcase_05 AC 26 ms
23,244 KB
testcase_06 AC 27 ms
23,616 KB
testcase_07 AC 22 ms
23,544 KB
testcase_08 AC 27 ms
23,904 KB
testcase_09 AC 21 ms
23,280 KB
testcase_10 AC 420 ms
24,024 KB
testcase_11 AC 1,540 ms
28,300 KB
testcase_12 AC 836 ms
24,264 KB
testcase_13 AC 1,046 ms
28,860 KB
testcase_14 AC 1,399 ms
27,508 KB
testcase_15 AC 1,588 ms
28,812 KB
testcase_16 AC 101 ms
23,508 KB
testcase_17 AC 1,017 ms
23,544 KB
testcase_18 AC 1,328 ms
28,048 KB
testcase_19 AC 1,341 ms
29,572 KB
testcase_20 AC 1,647 ms
29,016 KB
testcase_21 AC 1,598 ms
27,844 KB
testcase_22 AC 1,619 ms
27,840 KB
testcase_23 AC 21 ms
23,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

void main()
{
  auto n = readln.chomp.to!int;

  if (n == 1) {
    writeln("! 1");
    return;
  }

  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