結果

問題 No.305 鍵(2)
ユーザー maspymaspy
提出日時 2020-01-29 22:06:06
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 1,712 bytes
コンパイル時間 213 ms
コンパイル使用メモリ 11,068 KB
実行使用メモリ 24,600 KB
平均クエリ数 92.62
最終ジャッジ日時 2023-09-24 02:24:54
合計ジャッジ時間 1,768 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
24,160 KB
testcase_01 AC 44 ms
23,868 KB
testcase_02 AC 44 ms
24,144 KB
testcase_03 AC 44 ms
24,324 KB
testcase_04 AC 45 ms
23,960 KB
testcase_05 AC 44 ms
24,276 KB
testcase_06 AC 37 ms
24,600 KB
testcase_07 AC 44 ms
24,032 KB
testcase_08 AC 44 ms
23,964 KB
testcase_09 AC 44 ms
24,284 KB
testcase_10 AC 43 ms
24,140 KB
testcase_11 AC 43 ms
24,496 KB
testcase_12 AC 43 ms
23,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline

# DEBUG = True
DEBUG = False

class Interactive:
    def __init__(self):
        self.ques_cnt = 0
        self.create_data()
        
    def create_data(self):
        import random
        pwd = ''.join(map(str, (random.randint(0,9) for _ in range(10))))
        self.pwd = pwd
        print('created:', pwd)
        
    def resp_ques(self, *args):
        guess = args[0]
        if len(guess) != 10:
            raise ValueError
        x = sum(g == p for g,p in zip(guess, self.pwd))
        if x == 10:
            return '10 unlocked\n'
        else:
            return '{} locked\n'.format(x)
            
    def resp_ans(self, *args):
        pass
            
if DEBUG:
    interactive = Interactive()
    
def question(*args, offset=None):
    if offset is None:
        print(*args, flush=True)
    else:
        print(offset, *args, flush=True)
    if DEBUG:
        resp = interactive.resp_ques(*args)
        print(resp, end='')
        return resp
    else:
        return readline()
    
def answer(*args, offset=None):
    if offset is None:
        print(*args, flush=True)
    else:
        print(offset, *args, flush=True)
    if DEBUG:
        interactive.resp_ans(*args)
    else:
        exit()

def find_nth_value(n):
    A = [0] * 10
    best = -1
    ret = 0
    for i in range(10):
        A[n] = i
        word = ''.join(map(str,A))
        correct, status = question(word).split()
        correct = int(correct)
        if correct == 10:
            exit()
        if best < correct:
            best = correct
            ret = i
    return ret

A = [find_nth_value(n) for n in range(10)]    

x = ''.join(map(str,A))
question(x)
exit()
0