問題一覧 > 通常問題

No.305 Key (2)

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 256 MB / リアクティブ問題 (詳しくはこちら)
タグ : (AC するまで非表示) / 解いたユーザー数 229
作問者 : koyumeishi
お気に入りにしたユーザー ProblemId : 768 / 自分の提出
問題文最終更新日: 2026-06-25 09:26:19
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 128 (順位表) の他の問題:

Problem Statement

Yuki-kun has forgotten the PIN for the lock on his safe. Tell Yuki-kun numbers by guessing, and somehow help him unlock it.

The PIN is a 10-digit number (0000000000 to 9999999999). Output a 10-digit number (including leading zeros) to standard output.
If your output differs from the PIN,

X locked
is returned by the judge to standard input. Here, $X$ is the number of digits that match the PIN of the safe.
The lock is still not open, so use $X$ as a hint and try another number.

If your output matches the PIN,
10 unlocked
is returned by the judge to standard input.
The lock has been opened, so terminate your program. Any extra output after the query that unlocked the safe results in WA.

You may try as many times as you like within the time limit. (Apparently, about 7000 queries will result in TLE.)

Input / Output

This problem is a reactive problem. Perform input and output operations according to the problem statement.
In particular, do not forget to end each output with a newline and flush.
For notes on input and output in reactive problems, refer to the yukicoder wiki's summary of reactive problems, as well as No.246, No.253, and so on.

Judge Code (for reference)

This is the code used for judging. (C++; it reads the answer string from the file given as the first command-line argument.)
2016/05/04: The judge code has been changed. Invalid formats (such as outputting non-digit characters), multiple outputs on one line, and extra output after unlocking result in WA.

#include <iostream>
#include <fstream>
#include <cassert>
using namespace std;

string input(istream& is){
    string ret;
    getline(is, ret);         //回答コードから受け取った文字列
    assert(ret.size() == 10); //長さは 10
    for(char c : ret){        //数字のみかチェック
        assert('0' <= c && c <= '9');
    }
    return ret;
}

int main(int argc, char* argv[]){
    ifstream ifs(argv[1]);
    string ans = input(ifs);     //第一引数のファイルから正解の文字列を取得
    cerr << "Answer : " << ans << endl;

    while(1){
        string in = input(cin);  //標準入力から回答の文字列を取得
        if(in == ans){           //正解なら "10 unlocked" を出力して終了
            cout << "10 unlocked" << endl;
            if(cin >> in){  //余計な出力がないか確認
                cerr << "Wrong Answer : too many outputs" << endl;
                abort();
            }
            return 0;
        }else{                   //不正解なら "locked" を出力
            int x = 0;
            for(int i=0; i<10; i++){
                x += ans[i] == in[i];
            }
            cout << x << " locked" << endl;
        }
    }
    return 0;
}

Sample

Sample 1
PIN
0000000001

This is an example of input and output when the PIN is "0000000001".

Output
1234567890
0000000000
0000000001
Input
0 locked
9 locked
10 unlocked

In the first input, 0 digits match the PIN.
In the second input, the first 9 zeros match.
The third attempt unlocked the safe.
Output a 10-digit number, including leading zeros.

Sample 2
PIN
1234567890

This is an example of input and output when the PIN is "1234567890".

Output
0000000000
9999999999
1234500000
1234567899
1234567890
Input
1 locked
1 locked
6 locked
9 locked
10 unlocked

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。