結果
問題 |
No.282 おもりと天秤(2)
|
ユーザー |
|
提出日時 | 2021-03-23 12:27:44 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,308 bytes |
コンパイル時間 | 3,190 ms |
コンパイル使用メモリ | 207,528 KB |
最終ジャッジ日時 | 2025-01-19 21:12:19 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 TLE * 8 |
ソースコード
#include <bits/stdc++.h> using namespace std; void output(const vector<int> &v) { cout << "!"; for (int x: v) cout << " " << x+1; cout << endl; cout.flush(); } vector<char> query(const vector<int> &v, int n) { cout << "?"; for (int x: v) cout << " " << x + 1; cout << endl; cout.flush(); vector<char> s(n); for (int i = 0; i < n; i++) { cin >> s[i]; } return s; } vector<int> make(const set<int> &lo, const set<int> &hi, int n) { vector<int> cand; vector<int> vis(n); for (int x: lo) { if (!vis[x]) { vis[x] = 1; cand.push_back(x); } } if (cand.size() % 2) cand.push_back(-1); for (int x: hi) { if (!vis[x]) { vis[x] = 1; cand.push_back(x); } } while (cand.size() < 2 * n) cand.push_back(-1); return cand; } set<int> cross(const set<int> &a, const set<int> &b) { set<int> c; for (int x: a) { if (b.count(x)) c.insert(x); } return c; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> fixed(n); vector<int> ret(n); int s = 0, t = n-1; while (s <= t) { set<int> lo, hi; for (int i = 0; i < n; i++) { if (!fixed[i]) { lo.insert(i); hi.insert(i); } } while (lo.size() > 1 || hi.size() > 1) { vector<int> cand = make(lo, hi, n); vector<char> ans = query(cand, n); set<int> lo_t, hi_t; for (int i = 0; i < ans.size(); i++) { if (ans[i] == '<') { if (cand[2*i] == -1 && cand[2*i+1] == -1) {} else if (cand[2*i+1] == -1) { lo_t.insert(cand[2*i]); hi_t.insert(cand[2*i]); } else { lo_t.insert(cand[2*i]); hi_t.insert(cand[2*i+1]); } } else if (ans[i] == '>') { if (cand[2*i] == -1 && cand[2*i+1] == -1) {} else if (cand[2*i+1] == -1) { lo_t.insert(cand[2*i]); hi_t.insert(cand[2*i]); } else { lo_t.insert(cand[2*i+1]); hi_t.insert(cand[2*i]); } } } hi = cross(hi, hi_t); lo = cross(lo, lo_t); } ret[s++] = *lo.begin(); ret[t--] = *hi.begin(); fixed[*lo.begin()] = 1; fixed[*hi.begin()] = 1; } output(ret); return 0; }