結果

問題 No.305 鍵(2)
コンテスト
ユーザー tottoripaper
提出日時 2018-01-07 02:01:28
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
(最新)
TLE  
(最初)
実行時間 -
コード長 1,206 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 757 ms
コンパイル使用メモリ 82,340 KB
実行使用メモリ 28,976 KB
平均クエリ数 88919.16
最終ジャッジ日時 2026-03-31 03:41:17
合計ジャッジ時間 9,769 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 11 WA * 1 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <tuple>
using namespace std;

int ask(std::string S){
    std::cout << S << std::endl;

    int N;
    std::string T;
    std::cin >> N >> T;

    return N;
}

string find(string prefix, string suffix){
    for(int i=0;i<100000;++i){
        string s = to_string(i);
        while(s.size() < 5){
            s = '0' + s;
        }

        if(ask(prefix + s + suffix) == 5){
            return s;
        }
    }

    return "-1";
}

int main(){
    string notMatchedSuffix;
    {
        int matched = 100;
        for(int i=0;i<10;++i){
            string s = string(5, '0' + i);
            int n = ask(string(5, '0') + s);
            if(n < matched){
                notMatchedSuffix = s;
                matched = n;
            }
        }
    }
    
    string notMatchedPrefix;
    {
        int matched = 100;
        for(int i=0;i<10;++i){
            string s = string(5, '0' + i);
            int n = ask(s + string(5, '0'));
            if(n < matched){
                notMatchedPrefix = s;
                matched = n;
            }
        }
    }

    string res = find("", notMatchedSuffix) + find(notMatchedPrefix, "");
    std::cout << res << std::endl;
}
0