結果

問題 No.2357 Guess the Function
ユーザー Jeroen Op de BeekJeroen Op de Beek
提出日時 2023-06-23 21:38:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 1,000 ms
コード長 2,104 bytes
コンパイル時間 2,098 ms
コンパイル使用メモリ 212,552 KB
実行使用メモリ 24,288 KB
平均クエリ数 3.00
最終ジャッジ日時 2023-09-13 16:38:00
合計ジャッジ時間 3,363 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,832 KB
testcase_01 AC 24 ms
24,288 KB
testcase_02 AC 23 ms
23,532 KB
testcase_03 AC 23 ms
23,652 KB
testcase_04 AC 24 ms
23,232 KB
testcase_05 AC 24 ms
23,964 KB
testcase_06 AC 23 ms
23,412 KB
testcase_07 AC 24 ms
23,520 KB
testcase_08 AC 23 ms
24,204 KB
testcase_09 AC 24 ms
23,640 KB
testcase_10 AC 24 ms
23,364 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int whichx(std::vector<std::pair<int, int> >, int)’ 内:
main.cpp:54:1: 警告: 制御が非 void 関数の終りに到達しました [-Wreturn-type]
   54 | }
      | ^

ソースコード

diff #

#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';
}
0