結果
問題 | No.1959 Prefix MinMax |
ユーザー | milanis48663220 |
提出日時 | 2022-05-27 22:35:19 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 35 ms / 2,000 ms |
コード長 | 3,296 bytes |
コンパイル時間 | 1,193 ms |
コンパイル使用メモリ | 127,584 KB |
最終ジャッジ日時 | 2025-01-29 16:09:06 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 31 |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <cmath> #include <numeric> #include <functional> #include <cassert> #include <random> #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template<typename T> vector<vector<T>> vec2d(int n, int m, T v){ return vector<vector<T>>(n, vector<T>(m, v)); } template<typename T> vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){ return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v))); } template<typename T> void print_vector(vector<T> v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } vector<int> gen_permutation(int n) { random_device seed_gen; mt19937 engine(seed_gen()); vector<int> ans(n); for (int i = 0; i < n; i++) ans[i] = i; shuffle(ans.begin(), ans.end(), engine); return ans; } class Simulator{ public: int n, n_asked; vector<int> p; Simulator(int n): n(n), n_asked(0), p(gen_permutation(n)) {} vector<int> ask(vector<int> a){ n_asked++; assert(a.size() == n-1); vector<int> b(n); b[0] = p[0]; for(int i = 0; i < n-1; i++){ if(a[i] == 0){ b[i+1] = min(b[i], p[i+1]); }else{ b[i+1] = max(b[i], p[i+1]); } } return b; } void verify(vector<int> ans){ print_vector(p); print_vector(ans); for(int i = 0; i < n; i++){ assert(p[i] == ans[i]); } assert(n_asked <= 10); } }; // #define DEBUG void solve(){ int n; cin >> n; #ifdef DEBUG auto sim = Simulator(n); auto ask = [&](vector<int> a){ return sim.ask(a); }; auto verify = [&](vector<int> ans){ return sim.verify(ans); }; #else auto ask = [&](vector<int> a){ cout << "? "; for(int x: a) cout << x << ' '; cout << endl; vector<int> ans(n); for(int i = 0; i < n; i++){ cin >> ans[i]; ans[i]--; } return ans; }; auto verify = [&](vector<int> ans){ cout << "! "; for(int x: ans) cout << x+1 << ' '; cout << endl; }; #endif vector<int> ans(n); auto process = [&](vector<int> a){ auto b = ask(a); ans[0] = b[0]; for(int i = 1; i < n; i++){ if(b[i] != b[i-1]) ans[i] = b[i]; } }; vector<int> a(n-1); for(int i = 0; i < n-1; i++) a[i] = i%2; process(a); for(int i = 0; i < n-1; i++) a[i] = (i+1)%2; process(a); verify(ans); } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int t; cin >> t; while(t--) solve(); }