結果
問題 | No.1306 Exactly 2 Digits |
ユーザー | tokusakurai |
提出日時 | 2020-12-03 17:01:17 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 144 ms / 2,000 ms |
コード長 | 3,120 bytes |
コンパイル時間 | 2,529 ms |
コンパイル使用メモリ | 213,624 KB |
最終ジャッジ日時 | 2025-01-16 14:29:34 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 123 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define rep2(i, x, n) for(int i = x; i <= n; i++) #define rep3(i, x, n) for(int i = x; i >= n; i--) #define each(e, v) for(auto &e: v) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sz(x) (int)x.size() using ll = long long; using pii = pair<int, int>; using pil = pair<int, ll>; using pli = pair<ll, int>; using pll = pair<ll, ll>; const int MOD = 1000000007; //const int MOD = 998244353; const int inf = (1<<30)-1; const ll INF = (1LL<<60)-1; template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;}; template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;}; struct io_setup{ io_setup(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout << fixed << setprecision(15); } } io_setup; int N; pii query(int i, int j){ cout << "? " << j+1 << ' ' << i+1 << endl; int x, y; cin >> x >> y; return pii(x, y); } void answer(vector<pii> ans){ cout << '!'; each(e, ans) cout << ' ' << N*(e.second+1)+e.first; cout << endl; } int main(){ cin >> N; map<pii, vector<int>> mp; rep(i, N*(N-1)){ mp[query(0, i)].eb(i); } vector<pii> ans(N*(N-1), pii(-1, -1)); int l = 0; while(mp.count(pii(l, l))) --l; int r = 0; while(mp.count(pii(r, r))) ++r; int k = r-l-1; pii c1 = pii(0, N-1-k), c2 = pii(N-k, 0); c1.first -= l+1, c1.second -= l+1, c2.first -= l+1, c2.second -= l+1; map<pii, int> cmp; rep(i, N) rep(j, N-1){ int x = i-c1.first, y = j-c1.second; cmp[minmax(x, y)]++; } bool flag = true; each(e, mp){ if(sz(e.second) != cmp[e.first]) flag = false; } if(!flag) swap(c1, c2); auto [cx, cy] = c1; each(e, mp){ if(sz(e.second) == 1){ auto [dx, dy] = e.first; if(0 <= cx+dx && cx+dx < N && 0 <= cy+dy && cy+dy < N-1) ans[e.second[0]] = pii(cx+dx, cy+dy); else ans[e.second[0]] = pii(cx+dy, cy+dx); } } int id1 = 0, id2 = 0; rep(i, N*(N-1)){ if(ans[i].first == 0 && ans[i].second == 0) id1 = i; if(ans[i].first == N-1 && ans[i].second == N-2) id2 = i; } each(e, mp){ if(sz(e.second) == 2){ auto [dx, dy] = e.first; int p = e.second[0], q = e.second[1]; if(cx != cy){ auto [x, y] = query(id1, p); if((x == cx+dx && y == cy+dy) || (y == cx+dx && x == cy+dy)) ans[p] = pii(cx+dx, cy+dy), ans[q] = pii(cx+dy, cy+dx); else ans[q] = pii(cx+dx, cy+dy), ans[p] = pii(cx+dy, cy+dx); } else{ auto [x, y] = query(id2, p); if((N-1+x == cx+dx && N-2+y == cy+dy) || (N-1+y == cx+dx && N-2+x == cy+dy)) ans[p] = pii(cx+dx, cy+dy), ans[q] = pii(cx+dy, cy+dx); else ans[q] = pii(cx+dx, cy+dy), ans[p] = pii(cx+dy, cy+dx); } } } answer(ans); }