結果

問題 No.2848 Birthday Hit and Blow
ユーザー 👑 AngrySadEightAngrySadEight
提出日時 2024-06-05 01:58:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 13,270 bytes
コンパイル時間 1,251 ms
コンパイル使用メモリ 102,932 KB
実行使用メモリ 25,220 KB
平均クエリ数 158.00
最終ジャッジ日時 2024-07-17 02:36:25
合計ジャッジ時間 1,767 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
25,184 KB
testcase_01 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
using ll = long long;

int main() {
    vector<int> s = {354, 576, 789};
    map<string, vector<int>> mp;
    for (int i = 0; i <= 9; i++) {
        for (int j = 0; j <= 9; j++) {
            if (1 <= i && i <= 2) {
                continue;
            }
            if (1 <= j && j <= 2) {
                continue;
            }
            if (i == j) {
                continue;
            }
            string t = "";
            for (int k = 0; k < 3; k++) {
                int eat = 0;
                int bite = 0;
                if (s[k] / 100 == i) {
                    eat++;
                } else if ((s[k] % 100) / 10 == i || s[k] % 10 == i) {
                    bite++;
                }

                if (s[k] % 10 == j) {
                    eat++;
                } else if ((s[k] % 100) / 10 == j || s[k] / 100 == j) {
                    bite++;
                }
                t += (char)(eat + '0');
                t += (char)(bite + '0');
            }
            mp[t].push_back(i * 100 + j);
        }
    }
    mp["021000"].push_back(531);
    mp["010110"].push_back(731);
    mp["010001"].push_back(831);
    int T;
    cin >> T;
    while (T--) {
        int h1, h2, h3, b1, b2, b3;
        cout << "? 1354" << endl;
        cin >> h1 >> b1;
        if (h1 == -1 || b1 == -1) {
            return 0;
        }
        cout << "? 1576" << endl;
        cin >> h2 >> b2;
        if (h2 == -1 || b2 == -1) {
            return 0;
        }
        cout << "? 1789" << endl;
        cin >> h3 >> b3;
        if (h3 == -1 || b3 == -1) {
            return 0;
        }

        if (h1 >= 1 && h2 >= 1 && h3 >= 1) {
            h1--;
            h2--;
            h3--;
            vector<ll> ans = {1, -1, -1, -1};
            if (b1 == 1 && b2 == 0) {
                cout << "? 1023" << endl;
                int h4, b4;
                cin >> h4 >> b4;
                if (h4 == -1 || b4 == -1) {
                    return 0;
                }
                cout << "? 1203" << endl;
                int h5, b5;
                cin >> h5 >> b5;
                if (h5 == -1 || b5 == -1) {
                    return 0;
                }
                if (h4 == 4) {
                    cout << "! 1023" << endl;
                } else if (h5 == 4) {
                    cout << "! 1203" << endl;
                } else {
                    cout << "! 1230" << endl;
                }
                continue;
            } else if (h1 == 1) {
                ans[3] = 4;
            } else if (b1 == 1 && b2 == 1) {
                ans[3] = 5;
            } else if (h2 == 1) {
                ans[3] = 6;
            } else if (b2 == 1 && b3 == 1) {
                ans[3] = 7;
            } else if (b2 == 0 && b3 == 1) {
                ans[3] = 8;
            } else if (h3 == 1) {
                ans[3] = 9;
            }
            cout << "? " << ans[0] << "02" << ans[3] << endl;
            int h4, b4;
            cin >> h4 >> b4;
            if (h4 == -1 || b4 == -1) {
                return 0;
            }
            if (h4 == 4) {
                cout << "! " << ans[0] << "02" << ans[3] << endl;
            } else {
                cout << "! " << ans[0] << "20" << ans[3] << endl;
            }
        } else {
            vector<ll> ans = {0, -1, -1, -1};
            cout << "? 0789" << endl;
            int h4, b4;
            cin >> h4 >> b4;
            if (h4 == -1 || b4 == -1) {
                return 0;
            }
            if (b4 != b3) {
                b1--;
                b2--;
                b3--;
            }
            string res = "";
            res += (char)(h1 + '0');
            res += (char)(b1 + '0');
            res += (char)(h2 + '0');
            res += (char)(b2 + '0');
            res += (char)(h3 + '0');
            res += (char)(b3 + '0');
            vector<int> vec = mp[res];
            if (vec.size() == 1) {
                int val = vec[0];
                if (val / 100 != 0) {
                    ans[1] = val / 100;
                }
                if ((val / 10) % 10 != 0) {
                    ans[2] = (val / 10) % 10 != 0;
                }
                if (val % 10 != 0) {
                    ans[3] = val % 10;
                }
            } else {
                if (res == "000001") {
                    cout << "? 5678" << endl;
                    int h5, b5;
                    cin >> h5 >> b5;
                    if (h5 == -1 || b5 == -1) {
                        return 0;
                    }
                    if (h5 == 1) {
                        ans[3] = 8;
                    } else if (b5 == 1) {
                        ans[1] = 8;
                    } else {
                        ans[1] = 9;
                    }
                } else if (res == "000101") {
                    cout << "? 4597" << endl;
                    int h5, b5;
                    cin >> h5 >> b5;
                    if (h5 == -1 || b5 == -1) {
                        return 0;
                    }
                    if (h5 == 1) {
                        ans[3] = 7;
                    } else {
                        ans[1] = 6;
                        ans[3] = 8;
                    }
                } else if (res == "000102") {
                    cout << "? 4865" << endl;
                    int h5, b5;
                    cin >> h5 >> b5;
                    if (h5 == -1 || b5 == -1) {
                        return 0;
                    }
                    if (h5 == 1) {
                        ans[1] = 8;
                        ans[3] = 7;
                    } else {
                        ans[1] = 9;
                        ans[3] = 7;
                    }
                } else if (res == "000110") {
                    cout << "? 5684" << endl;
                    int h5, b5;
                    cin >> h5 >> b5;
                    if (h5 == -1 || b5 == -1) {
                        return 0;
                    }
                    if (h5 == 1) {
                        ans[1] = 6;
                        ans[3] = 9;
                    } else {
                        ans[1] = 7;
                    }
                } else if (res == "001001") {
                    cout << "? 4875" << endl;
                    int h5, b5;
                    cin >> h5 >> b5;
                    if (h5 == -1 || b5 == -1) {
                        return 0;
                    }
                    if (h5 == 1) {
                        ans[1] = 8;
                        ans[3] = 6;
                    } else {
                        ans[1] = 9;
                        ans[3] = 6;
                    }
                } else if (res == "010000") {
                    cout << "? 5673" << endl;
                    int h5, b5;
                    cin >> h5 >> b5;
                    if (h5 == -1 || b5 == -1) {
                        return 0;
                    }
                    if (h5 == 1) {
                        ans[3] = 3;
                    } else {
                        ans[1] = 4;
                    }
                } else if (res == "010001") {
                    cout << "? 5863" << endl;
                    int h5, b5;
                    cin >> h5 >> b5;
                    if (h5 == -1 || b5 == -1) {
                        return 0;
                    }
                    if (h5 == 2) {
                        ans[1] = 8;
                        ans[3] = 3;
                    } else if (h5 == 1 && b5 == 1) {
                        ans[1] = 8;
                        ans[2] = 3;
                        ans[3] = 1;
                    } else if (h5 == 1) {
                        ans[1] = 9;
                        ans[3] = 3;
                    } else {
                        ans[1] = 4;
                        ans[3] = 8;
                    }
                } else if (res == "010100") {
                    cout << "? 4785" << endl;
                    int h5, b5;
                    cin >> h5 >> b5;
                    if (h5 == -1 || b5 == -1) {
                        return 0;
                    }
                    if (h5 == 1) {
                        ans[3] = 5;
                    } else {
                        ans[1] = 6;
                        ans[3] = 3;
                    }
                } else if (res == "010101") {
                    cout << "? 3468" << endl;
                    int h5, b5;
                    cin >> h5 >> b5;
                    if (h5 == -1 || b5 == -1) {
                        return 0;
                    }
                    if (h5 == 1) {
                        ans[1] = 4;
                        ans[3] = 7;
                    } else if (b5 == 1) {
                        ans[1] = 8;
                        ans[3] = 5;
                    } else {
                        ans[1] = 9;
                        ans[3] = 5;
                    }
                } else if (res == "010110") {
                    cout << "? 9738" << endl;
                    int h5, b5;
                    cin >> h5 >> b5;
                    if (h5 == -1 || b5 == -1) {
                        return 0;
                    }
                    if (h5 == 2) {
                        ans[1] = 7;
                        ans[2] = 3;
                        ans[3] = 1;
                    } else {
                        ans[1] = 7;
                        ans[3] = 3;
                    }
                } else if (res == "011000") {
                    cout << "? 3478" << endl;
                    int h5, b5;
                    cin >> h5 >> b5;
                    if (h5 == -1 || b5 == -1) {
                        return 0;
                    }
                    if (h5 == 1) {
                        ans[1] = 4;
                        ans[3] = 6;
                    } else {
                        ans[1] = 5;
                    }
                } else if (res == "021000") {
                    cout << "? 9538" << endl;
                    int h5, b5;
                    cin >> h5 >> b5;
                    if (h5 == -1 || b5 == -1) {
                        return 0;
                    }
                    if (h5 == 2) {
                        ans[1] = 5;
                        ans[2] = 3;
                        ans[3] = 1;
                    } else {
                        ans[1] = 5;
                        ans[3] = 3;
                    }
                } else if (res == "100000") {
                    cout << "? 5378" << endl;
                    int h5, b5;
                    cin >> h5 >> b5;
                    if (h5 == -1 || b5 == -1) {
                        return 0;
                    }
                    if (h5 == 1) {
                        ans[1] = 3;
                    } else {
                        ans[3] = 4;
                    }
                } else if (res == "100001") {
                    cout << "? 5369" << endl;
                    int h5, b5;
                    cin >> h5 >> b5;
                    if (h5 == -1 || b5 == -1) {
                        return 0;
                    }
                    if (h5 == 1) {
                        ans[1] = 3;
                        ans[3] = 8;
                    } else if (b5 == 1) {
                        ans[1] = 9;
                        ans[3] = 4;
                    } else {
                        ans[1] = 8;
                        ans[3] = 4;
                    }
                }
            }
            if (ans[2] != -1) {
                cout << "! " << ans[0] << ans[1] << ans[2] << ans[3] << endl;
            } else if (ans[1] == -1) {
                cout << "? " << ans[0] << 12 << ans[3] << endl;
                int h6, b6;
                cin >> h6 >> b6;
                if (h6 == -1 || b6 == -1) {
                    return 0;
                }
                if (h6 == 4) {
                    cout << "! " << ans[0] << 12 << ans[3] << endl;
                } else {
                    cout << "! " << ans[0] << 21 << ans[3] << endl;
                }
            } else if (ans[3] == -1) {
                cout << "? " << ans[0] << ans[1] << 12 << endl;
                int h6, b6;
                cin >> h6 >> b6;
                if (h6 == -1 || b6 == -1) {
                    return 0;
                }
                if (h6 == 4) {
                    cout << "! " << ans[0] << ans[1] << 12 << endl;
                } else {
                    cout << "! " << ans[0] << ans[1] << 21 << endl;
                }
            } else {
                cout << "? " << ans[0] << ans[1] << 1 << ans[3] << endl;
                int h6, b6;
                cin >> h6 >> b6;
                if (h6 == -1 || b6 == -1) {
                    return 0;
                }
                if (h6 == 4) {
                    cout << "! " << ans[0] << ans[1] << 1 << ans[3] << endl;
                } else {
                    cout << "! " << ans[0] << ans[1] << 2 << ans[3] << endl;
                }
            }
        }
        int val;
        cin >> val;
        if (val == -1) {
            return 0;
        }
    }
}
0