結果

問題 No.2848 Birthday Hit and Blow
ユーザー apricity
提出日時 2025-03-02 18:27:07
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 17,475 bytes
コンパイル時間 1,640 ms
コンパイル使用メモリ 150,028 KB
実行使用メモリ 25,972 KB
平均クエリ数 542.00
最終ジャッジ日時 2025-03-02 18:27:19
合計ジャッジ時間 2,723 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<utility>
#include<tuple>
#include<cstdint>
#include<cstdio>
#include<iomanip>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include<cctype>
#include<chrono>
#include<random>
#include<cassert>
#include<cstddef>
#include<iterator>
#include<string_view>
#include<type_traits>

#ifdef LOCAL
#  include "debug_print.hpp"
#  define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#  define debug(...) (static_cast<void>(0))
#endif

using namespace std;
#define rep1(a)          for(int i = 0; i < a; i++)
#define rep2(i, a)       for(int i = 0; i < a; i++)
#define rep3(i, a, b)    for(int i = a; i < b; i++)
#define rep4(i, a, b, c) for(int i = a; i < b; i += c)
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(a)          for(int i = (a)-1; i >= 0; i--)
#define rrep2(i, a)       for(int i = (a)-1; i >= 0; i--)
#define rrep3(i, a, b)    for(int i = (b)-1; i >= a; i--)
#define rrep4(i, a, b, c) for(int i = (b)-1; i >= a; i -= c)
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
template <class T> using vc = vector<T>;
template <class T> using vvc = vector<vc<T>>;
template <class T> using vvvc = vector<vvc<T>>;
template <class T> using vvvvc = vector<vvvc<T>>;
template <class T> using vvvvvc = vector<vvvvc<T>>;
#define vv(type, name, h, ...) \
  vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...)   \
  vector<vector<vector<type>>> name( \
      h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)       \
  vector<vector<vector<vector<type>>>> name( \
      a, vector<vector<vector<type>>>(       \
             b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))
template<typename T> using PQ = priority_queue<T,vector<T>>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void yesno(bool flag) {cout << (flag?"Yes":"No") << "\n";}

template<typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << p.first << " " << p.second;
    return os;
}
template<typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
    is >> p.first >> p.second;
    return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    int s = (int)v.size();
    for (int i = 0; i < s; i++) os << (i ? " " : "") << v[i];
    return os;
}
template<typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (auto &x : v) is >> x;
    return is;
}
void in() {}
template<typename T, class... U>
void in(T &t, U &...u) {
    cin >> t;
    in(u...);
}
void out() { cout << "\n"; }
template<typename T, class... U, char sep = ' '>
void out(const T &t, const U &...u) {
    cout << t;
    if (sizeof...(u)) cout << sep;
    out(u...);
}
void outr() {}
template<typename T, class... U, char sep = ' '>
void outr(const T &t, const U &...u) {
    cout << t;
    outr(u...);
}

int h = -1, b = -1;

void query(string sq){
    out("?", sq);
    cout.flush();
    in(h,b);
    assert(h != -1 and b != -1);
}

void answer(string sa){
    out("!", sa);
    cout.flush();
    int vd; in(vd);
    assert(vd == 0);
}

void solve(){
    query("0456");
    if(h == 3 and b == 0){
        query("0416");
        if(h == 4 and b == 0) answer("0416");
        else answer("0426");
        return;
    }
    else if(h == 2 and b == 1){
        for(string s : {"0415", "0425", "0516", "0526"}){
            query(s);
            if(h == 4 and b == 0){
                answer(s);
                return;
            }
        }
    }
    else if(h == 1 and b == 2){
        for(string s : {"0615", "0625", "0614", "0624", "0514"}){
            query(s);
            if(h == 4 and b == 0){
                answer(s);
                return;
            }
        }
        answer("0524");
        return;
    }
    else if(h == 0 and b == 2){
        for(string s : {"1024", "1204", "1025", "1205"}){
            query(s);
            if(h == 4 and b == 0){
                answer(s);
                return;
            }
        }
    }
    else if(h == 0 and b == 1){
        query("1230");
        if(h == 4 and b == 0){
            answer("1230");
            return;
        }
        else if(h == 1 and b == 3){
            answer("1023");
            return;
        }
        else if(h == 2 and b == 2){
            answer("1203");
            return;
        }
        else if(h == 1 and b == 2){
            for(string s : {"1027", "1028", "1029"}){
                query(s);
                if(h == 4 and b == 0){
                    answer(s);
                    return;
                }
            }
        }
        else{
            for(string s : {"1207", "1208", "1209"}){
                query(s);
                if(h == 4 and b == 0){
                    answer(s);
                    return;
                }
            }
        }
    }
    else if(h == 1 and b == 0){
        query("0789");
        if(h == 3 and b == 0){
            for(string s : {"0719", "0729"}){
                query(s);
                if(h == 4 and b == 0){
                    answer(s);
                    return;
                }
            }
        }
        else if(h == 2 and b == 1){
            for(string s : {"0718", "0728", "0819", "0829"}){
                query(s);
                if(h == 4 and b == 0){
                    answer(s);
                    return;
                }
            }
        }
        else if(h == 2 and b == 0){
            query("0756");
            if(h == 2 and b == 0){
                query("0731");
                if(h == 4 and b == 0) {
                    answer("0731");
                    return;
                }
                else if(h == 3 and b == 0){
                    answer("0721");
                    return;
                }
                else if(h == 2 and b == 2){
                    answer("0713");
                    return;
                }
                else{
                    query("0712");
                    if(h == 4 and b == 0) answer("0712");
                    else answer("0723");
                    return;
                }
            }
            else{
                for(string s : {"0219", "0319", "0129"}){
                    query(s);
                    if(h == 4 and b == 0){
                        answer(s);
                        return;
                    }
                }
                answer("0329");
                return;
            }
        }
        else if(h == 1 and b == 2){
            query("0945");
            if(h == 2 and b == 0){
                for(string s : {"0917", "0927", "0918"}){
                    query(s);
                    if(h == 4 and b == 0){
                        answer(s);
                        return;
                    }
                }
                answer("0928");
                return;
            }
            if(h == 1 and b == 0){
                query("0817");
                if(h == 4 and b == 0) answer("0817");
                else answer("0827");
                return;
            }
        }
        else if(h == 1 and b == 0){
            for(string s : {"0123", "0213", "0312"}){
                query(s);
                if(h == 4 and b == 0){
                    answer(s);
                    return;
                }
            }
            answer("0321");
            return;
        }
        else{
            query("0978");
            if(h == 1 and b == 1){
                query("0417");
                if(h == 3 and b == 0){
                    query("0317");
                    if(h == 4 and b == 0) answer("0317");
                    else answer("0217");
                    return;
                }
                else if(h == 1 and b == 1){
                    query("0821");
                    if(h == 4 and b == 0) answer("0821");
                    else answer("0831");
                    return;
                }
                else if(h == 2 and b == 1){
                    answer("0127");
                    return;
                }
                else if(h == 1 and b == 0){
                    answer("0823");
                    return;
                }
                else{
                    for(string s : {"0812", "0813"}){
                        query(s);
                        if(h == 4 and b == 0){
                            answer(s);
                            return;
                        }
                    }
                    answer("0327");
                    return;
                }
            }
            else{
                query("0418");
                if(h == 3 and b == 0){
                    query("0318");
                    if(h == 4 and b == 0) answer("0318");
                    else answer("0218");
                    return;
                }
                else if(h == 1 and b == 1){
                    answer("0921");
                    return;
                }
                else if(h == 2 and b == 1){
                    answer("0128");
                    return;
                }
                else if(h == 1 and b == 0){
                    answer("0923");
                    return;
                }
                else{
                    for(string s : {"0912", "0913"}){
                        query(s);
                        if(h == 4 and b == 0){
                            answer(s);
                            return;
                        }
                    }
                    answer("0328");
                    return;
                }
            }
        }
    }
    else if(h == 2 and b == 0){
        query("0465");
        if(h == 2 and b == 0){
            query("3789");
            if(h == 0 and b == 0){
                query("0412");
                if(h == 4 and b == 0) answer("0412");
                else answer("0421");
                return;
            }
            else if(h == 1 and b == 0){
                query("0419");
                if(h == 4 and b == 0) answer("0419");
                else answer("0429");
                return;
            }
            else{
                query("0415");
                if(h == 3 and b == 0){
                    for(string s : {"0413", "0417"}){
                        query(s);
                        if(h == 4 and b == 0){
                            answer(s);
                            return;
                        }
                    }
                    answer("0418");
                    return;
                }
                else{
                    for(string s : {"0423", "0427"}){
                        query(s);
                        if(h == 4 and b == 0){
                            answer(s);
                            return;
                        }
                    }
                    answer("0428");
                    return;
                }
            }
        }
        else{
            query("0216");
            if(h == 4 and b == 0){
                answer("0216");
                return;
            }
            else if(h == 2 and b == 2){
                answer("0126");
                return;
            }
            else if(h == 3 and b == 0){
                for(string s : {"0316", "0716", "0816"}){
                    query(s);
                    if(h == 4 and b == 0){
                        answer(s);
                        return;
                    }
                }
                answer("0916");
                return;
            }
            else{
                for(string s : {"0326", "0726", "0826"}){
                    query(s);
                    if(h == 4 and b == 0){
                        answer(s);
                        return;
                    }
                }
                answer("0926");
                return;
            }
        }
    }
    else{
        query("0216");
        if(h == 3 and b == 0){
            query("0214");
            if(h == 4 and b == 0) answer("0214");
            else answer("0215");
            return;
        }
        else if(h == 2 and b == 2){
            query("1206");
            if(h == 4 and b == 0) answer("1206");
            else answer("0612");
            return;
        }
        else if(h == 1 and b == 3){
            query("0621");
            if(h == 4 and b == 0) answer("0621");
            else answer("1026");
            return;
        }
        else if(h == 2 and b == 1){
            query("0613");
            if(h == 4 and b == 0) {
                answer("0613");
                return;
            }
            else if(h == 2 and b == 0){
                answer("0512");
                return;
            }
            else{
                for(string s : {"0617", "0618"}){
                    query(s);
                    if(h == 4 and b == 0){
                        answer(s);
                        return;
                    }
                }
                answer("0619");
                return;
            }
        }
        else if(h == 1 and b == 2){
            query("0623");
            if(h == 4 and b == 0) {
                answer("0623");
                return;
            }
            else if(h == 2 and b == 0){
                for(string s : {"0124", "0125"}){
                    query(s);
                    if(h == 4 and b == 0){
                        answer(s);
                        return;
                    }
                }
                answer("0521");
                return;
            }
            else{
                for(string s : {"0627", "0628"}){
                    query(s);
                    if(h == 4 and b == 0){
                        answer(s);
                        return;
                    }
                }
                answer("0629");
                return;
            }
        }
        else if(h == 2 and b == 0){
            query("0215");
            if(h == 3 and b == 0){
                for(string s : {"0315", "0715", "0815"}){
                    query(s);
                    if(h == 4 and b == 0){
                        answer(s);
                        return;
                    }
                }
                answer("0915");
                return;
            }
            else if(h == 2 and b == 1){
                for(string s : {"0513", "0517", "0518"}){
                    query(s);
                    if(h == 4 and b == 0){
                        answer(s);
                        return;
                    }
                }
                answer("0519");
                return;
            }
            else{
                for(string s : {"0314", "0714", "0814"}){
                    query(s);
                    if(h == 4 and b == 0){
                        answer(s);
                        return;
                    }
                }
                answer("0914");
                return;
            }
        }
        else{
            query("0523");
            if(h == 4 and b == 0){
                answer("0523");
                return;
            }
            else if(h == 2 and b == 2){
                answer("0325");
                return;
            }
            else if(h == 3 and b == 0){
                for(string s : {"0527", "0528"}){
                    query(s);
                    if(h == 4 and b == 0){
                        answer(s);
                        return;
                    }
                }
                answer("0529");
                return;
            }
            else if(h == 2 and b == 0){
                for(string s : {"0724", "0824"}){
                    query(s);
                    if(h == 4 and b == 0){
                        answer(s);
                        return;
                    }
                }
                answer("0924");
                return;
            }
            else{
                query("0725");
                if(h == 4 and b == 0) {
                    answer("0725");
                    return;
                }
                else if(h == 3 and b == 0){
                    query("0825");
                    if(h == 4 and b == 0) answer("0825");
                    else answer("0925");
                    return;
                }
                else if(h == 2 and b == 0){
                    answer("0324");
                    return;
                }
                else{
                    answer("0531");
                    return;
                }
            }
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int tc; in(tc);
    while(tc--){
        solve();
    }
}
0