結果

問題 No.282 おもりと天秤(2)
コンテスト
ユーザー ゴリポン先生
提出日時 2026-07-11 15:58:59
言語 D
(dmd 2.112.0)
コンパイル:
dmd -fPIE -m64 -w -wi -O -release -inline -I/opt/dmd/src/druntime/import/ -I/opt/dmd/src/phobos -L-L/opt/dmd/linux/lib64/ -fPIC _filename_
実行:
./Main
結果
AC  
実行時間 65 ms / 5,000 ms
+ 0µs
コード長 1,161 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,779 ms
コンパイル使用メモリ 191,104 KB
実行使用メモリ 5,888 KB
平均クエリ数 30.58
最終ジャッジ日時 2026-07-11 15:59:11
合計ジャッジ時間 5,946 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

module main;
// https://yukicoder.me/submissions/46424 より
// インタラクティブ問題、バイトニックソート
import std;

// ceil(log_2(n))を求める
int ceilLog2(T)(T n)
{
	int x = 0;
	T one = 1;
	while (one << x < n) x++;
	return x;
}

void main()
{
	// 入力
	int N = readln.chomp.to!int;
	// 答えの計算と出力
	int M = ceilLog2(N);
	auto A = new int[](1 << M);
	foreach (i; 0 .. N)
		A[i] = i + 1;
	foreach (fb; 1 .. M + 1) {
		foreach_reverse (sb; 0 .. fb) {
			auto Q = new int[](2 * N);
			auto pos = new int[](2 * N);
			int p = 0;
			foreach (i; 0 .. 1 << M) {
				if (((i >> fb) & 1) ^ ((i >> sb) & 1)) {
					if (A[i] == 0) {
						swap(A[i], A[i ^ (1 << sb)]);
						continue;
					} else if (A[i ^ (1 << sb)] == 0)
						continue;
					pos[p] = i;
					Q[p++] = A[i];
					pos[p] = i ^ (1 << sb);
					Q[p++] = A[i ^ (1 << sb)];
				}
			}
			writefln("? %(%d %)", Q);
			stdout.flush;
			auto ans = readln.split;
			for (int i = 0; i < p; i += 2) {
				int l = pos[i], r = pos[i + 1];
				if (ans[i / 2] == "<")
					swap(A[l], A[r]);
			}
		}
	}
	A = A.remove!(a => a == 0);
	writefln("! %(%d %)", A);
	stdout.flush;
}
0