結果
| 問題 |
No.282 おもりと天秤(2)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-01-09 17:31:21 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 2,030 ms / 5,000 ms |
| コード長 | 1,517 bytes |
| コンパイル時間 | 1,332 ms |
| コンパイル使用メモリ | 156,216 KB |
| 実行使用メモリ | 28,760 KB |
| 平均クエリ数 | 267.12 |
| 最終ジャッジ日時 | 2024-06-12 23:24:43 |
| 合計ジャッジ時間 | 22,187 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 24 |
ソースコード
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)); }
}