結果

問題 No.1306 Exactly 2 Digits
ユーザー tkmst201tkmst201
提出日時 2020-12-03 19:52:00
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,618 bytes
コンパイル時間 2,372 ms
コンパイル使用メモリ 212,732 KB
実行使用メモリ 24,492 KB
平均クエリ数 1236.78
最終ジャッジ日時 2023-09-24 08:30:13
合計ジャッジ時間 32,595 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 25 ms
24,072 KB
testcase_02 WA -
testcase_03 AC 26 ms
23,856 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 25 ms
23,592 KB
testcase_07 AC 28 ms
24,288 KB
testcase_08 AC 26 ms
23,544 KB
testcase_09 WA -
testcase_10 AC 26 ms
24,228 KB
testcase_11 AC 25 ms
23,676 KB
testcase_12 WA -
testcase_13 AC 26 ms
24,264 KB
testcase_14 AC 26 ms
23,424 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 26 ms
23,568 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 27 ms
23,448 KB
testcase_22 WA -
testcase_23 AC 28 ms
23,868 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 26 ms
23,592 KB
testcase_33 AC 27 ms
24,000 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 27 ms
23,844 KB
testcase_39 AC 27 ms
23,424 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 27 ms
23,436 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
testcase_73 WA -
testcase_74 WA -
testcase_75 WA -
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 WA -
testcase_83 WA -
testcase_84 WA -
testcase_85 WA -
testcase_86 WA -
testcase_87 WA -
testcase_88 WA -
testcase_89 WA -
testcase_90 WA -
testcase_91 WA -
testcase_92 WA -
testcase_93 WA -
testcase_94 WA -
testcase_95 WA -
testcase_96 WA -
testcase_97 WA -
testcase_98 WA -
testcase_99 WA -
testcase_100 WA -
testcase_101 WA -
testcase_102 WA -
testcase_103 WA -
testcase_104 WA -
testcase_105 WA -
testcase_106 WA -
testcase_107 WA -
testcase_108 WA -
testcase_109 WA -
testcase_110 WA -
testcase_111 WA -
testcase_112 WA -
testcase_113 WA -
testcase_114 WA -
testcase_115 WA -
testcase_116 WA -
testcase_117 WA -
testcase_118 WA -
testcase_119 WA -
testcase_120 WA -
testcase_121 WA -
testcase_122 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	auto query = [](int i, int j) -> pii {
		cout << "? " << i << " " << j << endl;
		int p, q;
		cin >> p >> q;
		return {p, q};
	};
	
	if (N == 2) {
		auto res = query(1, 2);
		if (res.second == 1) puts("! 1 2");
		else puts("! 2 1");
		return 0;
	}
	
	vector<pii> res(N * N - N);
	FOR(i, 1, res.size()) res[i] = query(1, i + 1);
	
	const int bias = N;
	vector<int> cnt(2 * N);
	FOR(i, 1, res.size()) {
		++cnt[res[i].first + bias];
		++cnt[res[i].second + bias];
	}
	
	int mx = -INF, mn = INF;
	REP(i, cnt.size()) {
		if (!cnt[i]) continue;
		chmax(mx, i - bias);
		chmin(mn, i - bias);
	}
	
	vector<pii> ans(res.size(), {-INF, -INF});
	if (cnt[mx + bias] == N - 1) ans[0] = {mn + (N - 1), mx}; // A_1 - 1 < B
	else if (cnt[mx + bias] == N - 2) ans[0] = {1 + mx, mn + (N - 1)}; // A_1 - 1 > B
	else ans[0] = {mx + 1, mx}; // A_1 - 1 = B
	
	map<pii, vector<int>> mm; // (p, q) = {idx...}
	FOR(i, 1, res.size())  mm[res[i]].emplace_back(i);
	
	int tidx = 0;
	for (const auto & [p, vec] : mm) {
		if (vec.size() != 1) continue;
		int t1 = ans[0].first - p.first, t2 = ans[0].second - p.second;
		if (!(1 <= t1 && t1 < N && 0 <= t2 && t2 < N)) {
			t1 = ans[0].first - p.second;
			t2 = ans[0].second - p.first;
		}
		ans[vec[0]] = {t1, t2};
		if (ans[0].first - 1 < ans[0].second && ans[vec[0]] == pii{N - 1, 0}) tidx = vec[0];
		if (ans[0].first - 1 >= ans[0].second && ans[vec[0]] == pii{1, N - 1}) tidx = vec[0];
	}
	
	for (const auto & [p, vec] : mm) {
		if (vec.size() == 1) continue;
		auto q = query(tidx + 1, vec[0] + 1);
		pii pred1 {ans[0].first - p.first, ans[0].second - p.second};
		pii pred2 {ans[0].first - p.second, ans[0].second - p.first};
		if (ans[0].first - 1 > ans[0].second) ans[vec[0]] = {N - 1 - q.second, 0 - q.first};
		else ans[vec[0]] = {1 - q.first, N - 1 - q.second};
		ans[vec[1]] = ans[vec[0]] == pred1 ? pred2 : pred1;
	}
	
	cout << "! ";
	REP(i, ans.size()) cout << ans[i].first * N + ans[i].second << " \n"[i + 1 == ans.size()];
	cout << flush;
}
0