結果

問題 No.1306 Exactly 2 Digits
ユーザー tkmst201tkmst201
提出日時 2020-12-04 12:50:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 133 ms / 2,000 ms
コード長 2,610 bytes
コンパイル時間 2,437 ms
コンパイル使用メモリ 213,376 KB
実行使用メモリ 24,384 KB
平均クエリ数 1236.78
最終ジャッジ日時 2023-09-24 08:57:44
合計ジャッジ時間 15,855 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
23,880 KB
testcase_01 AC 23 ms
23,892 KB
testcase_02 AC 23 ms
23,292 KB
testcase_03 AC 22 ms
23,700 KB
testcase_04 AC 21 ms
23,544 KB
testcase_05 AC 23 ms
23,244 KB
testcase_06 AC 23 ms
23,412 KB
testcase_07 AC 24 ms
23,376 KB
testcase_08 AC 24 ms
24,024 KB
testcase_09 AC 24 ms
23,712 KB
testcase_10 AC 24 ms
23,508 KB
testcase_11 AC 23 ms
24,216 KB
testcase_12 AC 23 ms
23,784 KB
testcase_13 AC 24 ms
24,036 KB
testcase_14 AC 24 ms
23,256 KB
testcase_15 AC 24 ms
23,880 KB
testcase_16 AC 25 ms
23,868 KB
testcase_17 AC 25 ms
24,204 KB
testcase_18 AC 27 ms
23,868 KB
testcase_19 AC 25 ms
23,376 KB
testcase_20 AC 23 ms
23,532 KB
testcase_21 AC 22 ms
23,508 KB
testcase_22 AC 22 ms
23,616 KB
testcase_23 AC 24 ms
23,544 KB
testcase_24 AC 24 ms
23,520 KB
testcase_25 AC 23 ms
23,880 KB
testcase_26 AC 25 ms
24,372 KB
testcase_27 AC 24 ms
23,376 KB
testcase_28 AC 24 ms
23,376 KB
testcase_29 AC 24 ms
23,880 KB
testcase_30 AC 24 ms
24,228 KB
testcase_31 AC 25 ms
23,508 KB
testcase_32 AC 26 ms
23,640 KB
testcase_33 AC 25 ms
23,388 KB
testcase_34 AC 26 ms
23,400 KB
testcase_35 AC 24 ms
23,628 KB
testcase_36 AC 25 ms
23,868 KB
testcase_37 AC 26 ms
24,240 KB
testcase_38 AC 25 ms
23,364 KB
testcase_39 AC 26 ms
24,036 KB
testcase_40 AC 25 ms
23,652 KB
testcase_41 AC 26 ms
24,252 KB
testcase_42 AC 26 ms
23,364 KB
testcase_43 AC 27 ms
24,204 KB
testcase_44 AC 27 ms
23,520 KB
testcase_45 AC 27 ms
23,400 KB
testcase_46 AC 27 ms
23,400 KB
testcase_47 AC 27 ms
23,256 KB
testcase_48 AC 30 ms
23,880 KB
testcase_49 AC 29 ms
23,868 KB
testcase_50 AC 30 ms
23,700 KB
testcase_51 AC 30 ms
23,364 KB
testcase_52 AC 33 ms
23,244 KB
testcase_53 AC 36 ms
23,508 KB
testcase_54 AC 32 ms
23,352 KB
testcase_55 AC 37 ms
23,868 KB
testcase_56 AC 37 ms
23,520 KB
testcase_57 AC 39 ms
23,796 KB
testcase_58 AC 41 ms
23,796 KB
testcase_59 AC 39 ms
24,024 KB
testcase_60 AC 48 ms
24,216 KB
testcase_61 AC 48 ms
23,700 KB
testcase_62 AC 51 ms
23,376 KB
testcase_63 AC 52 ms
24,384 KB
testcase_64 AC 52 ms
23,796 KB
testcase_65 AC 55 ms
23,508 KB
testcase_66 AC 61 ms
23,664 KB
testcase_67 AC 64 ms
24,336 KB
testcase_68 AC 62 ms
23,628 KB
testcase_69 AC 67 ms
23,892 KB
testcase_70 AC 67 ms
23,700 KB
testcase_71 AC 71 ms
23,388 KB
testcase_72 AC 69 ms
23,364 KB
testcase_73 AC 67 ms
23,868 KB
testcase_74 AC 79 ms
23,700 KB
testcase_75 AC 75 ms
23,400 KB
testcase_76 AC 86 ms
23,292 KB
testcase_77 AC 90 ms
23,232 KB
testcase_78 AC 93 ms
23,400 KB
testcase_79 AC 104 ms
23,400 KB
testcase_80 AC 103 ms
23,640 KB
testcase_81 AC 90 ms
23,292 KB
testcase_82 AC 109 ms
23,232 KB
testcase_83 AC 115 ms
24,240 KB
testcase_84 AC 124 ms
23,388 KB
testcase_85 AC 127 ms
23,700 KB
testcase_86 AC 104 ms
23,880 KB
testcase_87 AC 110 ms
23,700 KB
testcase_88 AC 133 ms
23,628 KB
testcase_89 AC 109 ms
24,024 KB
testcase_90 AC 97 ms
23,376 KB
testcase_91 AC 109 ms
24,096 KB
testcase_92 AC 103 ms
24,204 KB
testcase_93 AC 117 ms
23,388 KB
testcase_94 AC 98 ms
23,400 KB
testcase_95 AC 110 ms
23,796 KB
testcase_96 AC 96 ms
23,292 KB
testcase_97 AC 97 ms
23,532 KB
testcase_98 AC 96 ms
23,496 KB
testcase_99 AC 112 ms
23,616 KB
testcase_100 AC 111 ms
23,796 KB
testcase_101 AC 120 ms
23,400 KB
testcase_102 AC 99 ms
23,892 KB
testcase_103 AC 105 ms
23,616 KB
testcase_104 AC 106 ms
23,388 KB
testcase_105 AC 107 ms
24,336 KB
testcase_106 AC 97 ms
23,352 KB
testcase_107 AC 110 ms
23,376 KB
testcase_108 AC 99 ms
23,292 KB
testcase_109 AC 122 ms
23,640 KB
testcase_110 AC 98 ms
23,688 KB
testcase_111 AC 99 ms
24,024 KB
testcase_112 AC 93 ms
23,244 KB
testcase_113 AC 127 ms
23,520 KB
testcase_114 AC 126 ms
23,796 KB
testcase_115 AC 110 ms
23,364 KB
testcase_116 AC 130 ms
23,712 KB
testcase_117 AC 114 ms
24,012 KB
testcase_118 AC 120 ms
23,352 KB
testcase_119 AC 104 ms
23,916 KB
testcase_120 AC 95 ms
23,280 KB
testcase_121 AC 116 ms
24,024 KB
testcase_122 AC 117 ms
23,628 KB
権限があれば一括ダウンロードができます

ソースコード

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 {
		++i; ++j;
		cout << "? " << i << " " << j << endl;
		int p, q;
		cin >> p >> q;
		return {p, q};
	};
	
	if (N == 2) {
		auto res = query(0, 1);
		if (res.second == 1) puts("! 3 2");
		else puts("! 2 3");
		return 0;
	}
	
	vector<pii> res(N * N - N);
	FOR(i, 1, res.size()) res[i] = query(0, i);
	
	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[mn + bias] == N || cnt[mn + bias] == 2 * N - 1 || cnt[mn + bias] == 2 * N - 3) ans[0] = {N - 1 + mn, mx};// A_1 <= B_1
	else ans[0] = {1 + mx, N - 1 + mn}; // A_1 > B_1
	
	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 <= ans[0].second && ans[vec[0]] == pii{N - 1, 0}) tidx = vec[0];
		if (ans[0].first > 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 = tidx == 0 ? res[vec[0]] : query(tidx, vec[0]);
		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 <= 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