結果
問題 | No.2357 Guess the Function |
ユーザー |
|
提出日時 | 2023-06-23 21:38:47 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 38 ms / 1,000 ms |
コード長 | 2,104 bytes |
コンパイル時間 | 2,647 ms |
コンパイル使用メモリ | 207,232 KB |
最終ジャッジ日時 | 2025-02-15 00:41:37 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 10 |
コンパイルメッセージ
main.cpp: In function ‘int whichx(std::vector<std::pair<int, int> >, int)’: main.cpp:54:1: warning: control reaches end of non-void function [-Wreturn-type] 54 | } | ^
ソースコード
#include "bits/stdc++.h" using namespace std; #define all(x) begin(x),end(x) template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; } #define debug(a) cerr << "(" << #a << ": " << a << ")\n"; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int,int> pi; const int mxN = 1e5+1, oo = 1e9; bool rec(const vector<pi>& ps, int tr=2) { if(tr==1 and ps.size()>100) return false; if(tr==0) { return ps.size()==1; } for(int x=1;x<=100;++x) { map<int,vector<pi>> who; for(auto [a,b] : ps) { who[(a+x)%b].push_back({a,b}); } bool bad=0; for(const auto& [res,v] : who) { if(!rec(v,tr-1)) { bad=1; break; } } if(!bad) { return true; } } return false; } int whichx(vector<pi> ps, int tr=2) { if(tr==2) return 50; for(int x=1;x<=100;++x) { map<int,vector<pi>> who; for(auto [a,b] : ps) { who[(a+x)%b].push_back({a,b}); } bool bad=0; for(auto [res,v] : who) { if(!rec(v,tr-1)) { bad=1; break; } } if(!bad) { return x; } } } int main() { vector<pi> vs; for(int a=0;a<100;++a) for(int b=a+1;b<=100;++b) { vs.push_back({a,b}); } int tr=2; // debug(rec(vs)); while(vs.size()>1) { int x = whichx(vs,tr); cout << "? " << x << '\n'; int res; cin >> res; vs.erase(partition(all(vs),[&](pi p) {return (p.first+x)%p.second==res;}),vs.end()); tr--; } cout << "! " << vs[0].first << ' ' << vs[0].second << '\n'; }