結果

問題 No.282 おもりと天秤(2)
コンテスト
ユーザー pekempey
提出日時 2015-09-19 09:56:48
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1,238 ms / 5,000 ms
コード長 1,190 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,149 ms
コンパイル使用メモリ 180,288 KB
実行使用メモリ 28,976 KB
平均クエリ数 440.67
最終ジャッジ日時 2026-03-31 10:41:23
合計ジャッジ時間 12,968 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#define rep(i, a) rep2 (i, 0, a)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a) repr2 (i, 0, a)
#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define chmin(a, b) ((b) < a && (a = (b), true))
#define chmax(a, b) (a < (b) && (a = (b), true))
#define rng(a) (a).begin(), (a).end()
using namespace std;
typedef long long ll;

vector<int> query(vector<int> a, bool odd) {
	int n = a.size();
	cout << "?";
	rep (i, n - 1) {
		if (i % 2 == odd) {
			cout << " " << a[i] << " " << a[i + 1];
		} else {
			cout << " 0 0";
		}
	}
	cout << " 0 0" << endl;
	vector<int> res;
	rep (i, n) {
		string s;
		cin >> s;
		if (s[0] == '=') res.push_back(0);
		else if (s[0] == '<') res.push_back(-1);
		else res.push_back(1);
	}
	return res;
}

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep (i, n) a[i] = i + 1;
	rep (i, n) {
		auto even = query(a, false);
		for (int i = 0; i + 1 < n; i += 2) {
			if (even[i] > 0) swap(a[i], a[i + 1]);
		}
		auto odd = query(a, true);
		for (int i = 1; i + 1 < n; i += 2) {
			if (odd[i] > 0) swap(a[i], a[i + 1]);
		}
	}
	cout << "!";
	rep (i, n) cout << " " << a[i];
	cout << endl;
    return 0;
}
0