結果
| 問題 |
No.1306 Exactly 2 Digits
|
| コンテスト | |
| ユーザー |
emthrm
|
| 提出日時 | 2020-12-03 01:12:26 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 606 ms / 2,000 ms |
| コード長 | 2,991 bytes |
| コンパイル時間 | 3,085 ms |
| コンパイル使用メモリ | 226,968 KB |
| 最終ジャッジ日時 | 2025-01-16 13:46:54 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 123 |
ソースコード
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
IOSetup() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::cout << fixed << setprecision(20);
}
} iosetup;
pair<int, int> query(int i, int j) {
cout << "? " << i + 1 << ' ' << j + 1 << endl;
int p, q; cin >> p >> q;
return {p, q};
}
int main() {
int n; cin >> n;
map<vector<pair<int, int>>, pair<int, int>> mp;
FOR(si, 1, n) REP(sj, n) {
vector<pair<int, int>> v;
FOR(i, 1, n) REP(j, n) {
if (i != si || j != sj) v.emplace_back(minmax(si - i, sj - j));
}
sort(ALL(v));
mp[v] = {si, sj};
}
int m = n * n - n;
vector<pair<int, int>> res(m), sea;
FOR(i, 1, m) {
auto [p, q] = query(0, i);
res[i] = {p, q};
sea.emplace_back(p, q);
}
sort(ALL(sea));
vector<pair<int, int>> ans(m, {-1, -1});
ans[0] = mp[sea];
map<pair<int, int>, vector<pair<int, int>>> mp2;
map<pair<int, int>, int> rev;
rev[ans[0]] = 0;
FOR(i, 1, n) REP(j, n) {
if (i != ans[0].first || j != ans[0].second) mp2[minmax(ans[0].first - i, ans[0].second - j)].emplace_back(i, j);
}
FOR(idx, 1, m) {
if (mp2[res[idx]].size() == 1) {
ans[idx] = mp2[res[idx]][0];
rev[ans[idx]] = idx;
}
}
FOR(idx, 1, m) {
if (mp2[res[idx]].size() == 2) {
auto [p1, q1] = mp2[res[idx]][0];
auto [p2, q2] = mp2[res[idx]][1];
for (auto [pr, pos] : rev) {
auto [p, q] = pr;
if (minmax(p - p1, q - q1) != minmax(p - p2, q - q2)) {
auto [res_p, res_q] = query(pos, idx);
if (res_p == minmax(p - p1, q - q1).first && res_q == minmax(p - p1, q - q1).second) {
ans[idx] = {p1, q1};
mp2[res[idx]].erase(mp2[res[idx]].begin());
} else {
assert(res_p == minmax(p - p2, q - q2).first && res_q == minmax(p - p2, q - q2).second);
ans[idx] = {p2, q2};
mp2[res[idx]].erase(mp2[res[idx]].begin() + 1);
}
// rev[ans[idx]] = idx;
break;
}
}
} else {
ans[idx] = mp2[res[idx]][0];
// rev[ans[idx]] = idx;
}
}
cout << "! ";
REP(i, m) {
cout << ans[i].first * n + ans[i].second;
if (i + 1 == m) {
cout << endl;
} else {
cout << ' ';
}
}
return 0;
}
emthrm