結果

問題 No.282 おもりと天秤(2)
ユーザー pekempeypekempey
提出日時 2015-09-19 00:19:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,785 ms / 5,000 ms
コード長 1,510 bytes
コンパイル時間 2,498 ms
コンパイル使用メモリ 154,632 KB
実行使用メモリ 24,492 KB
平均クエリ数 267.12
最終ジャッジ日時 2023-09-23 21:36:15
合計ジャッジ時間 21,329 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,436 KB
testcase_01 AC 30 ms
23,436 KB
testcase_02 AC 25 ms
23,736 KB
testcase_03 AC 26 ms
24,108 KB
testcase_04 AC 25 ms
24,288 KB
testcase_05 AC 29 ms
23,724 KB
testcase_06 AC 30 ms
23,712 KB
testcase_07 AC 26 ms
24,048 KB
testcase_08 AC 32 ms
24,480 KB
testcase_09 AC 24 ms
23,676 KB
testcase_10 AC 458 ms
23,592 KB
testcase_11 AC 1,707 ms
24,432 KB
testcase_12 AC 896 ms
23,472 KB
testcase_13 AC 1,152 ms
24,120 KB
testcase_14 AC 1,551 ms
24,492 KB
testcase_15 AC 1,738 ms
23,724 KB
testcase_16 AC 107 ms
23,448 KB
testcase_17 AC 1,059 ms
23,676 KB
testcase_18 AC 1,445 ms
24,108 KB
testcase_19 AC 1,439 ms
23,712 KB
testcase_20 AC 1,757 ms
23,604 KB
testcase_21 AC 1,785 ms
24,360 KB
testcase_22 AC 1,776 ms
23,868 KB
testcase_23 AC 22 ms
23,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;

int n;
int C[555][555];
int a[555];

void query(vector<pair<int, int>> v) {
	v.resize(n, make_pair(-1, -1));
	cout << "?";
	rep (i, v.size()) cout << " " << v[i].first + 1 << " " << v[i].second + 1;
	cout << endl;
	rep (i, n) {
		string str;
		cin >> str;
		if (v[i].first == -1) continue;
		int a = v[i].first;
		int b = v[i].second;
		int c;
		if (str[0] == '<') {
			c = -1;
		} else if (str[0] == '>') {
			c = 1;
		} else {
			c = 0;
		}
		C[a][b] = c;
		C[b][a] = -c;
	}
}

bool checked[555][555];

int main() {
	cin >> n;
	rep (i, n) a[i] = i;
	vector<bool> used(n);
	int num = 0;
	while (num < n * (n - 1) / 2) {
		fill(rng(used), false);
		vector<pair<int, int>> q;
		rep (i, n) {
			rep2 (j, i + 1, n) {
				if (!checked[i][j] && !used[i] && !used[j]) {
					q.emplace_back(i, j);
					checked[i][j] = true;
					num++;
					used[i] = true;
					used[j] = true;
				}
				if (q.size() == n) break;
			}
			if (q.size() == n) break;
		}
		query(q);
	}
	rep (i, n) {
		rep2 (j, i, n) {
			if (C[a[i]][a[j]] > 0) swap(a[i], a[j]);
		}
	}
	cout << "!";
	rep (i, n) cout << " " << a[i] + 1;
	cout << endl;
	return 0;
}
0