結果

問題 No.355 数当てゲーム(2)
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-04-04 18:18:07
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,119 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 10,952 KB
実行使用メモリ 25,664 KB
平均クエリ数 5.42
最終ジャッジ日時 2023-09-23 23:42:08
合計ジャッジ時間 5,773 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
25,468 KB
testcase_01 AC 50 ms
25,148 KB
testcase_02 AC 55 ms
25,664 KB
testcase_03 AC 53 ms
25,040 KB
testcase_04 AC 58 ms
24,888 KB
testcase_05 AC 51 ms
25,444 KB
testcase_06 AC 49 ms
25,208 KB
testcase_07 AC 52 ms
25,468 KB
testcase_08 AC 48 ms
25,456 KB
testcase_09 AC 50 ms
25,148 KB
testcase_10 AC 52 ms
25,392 KB
testcase_11 AC 49 ms
25,316 KB
testcase_12 AC 51 ms
24,844 KB
testcase_13 AC 53 ms
25,024 KB
testcase_14 AC 53 ms
25,332 KB
testcase_15 AC 50 ms
25,148 KB
testcase_16 AC 52 ms
25,268 KB
testcase_17 AC 51 ms
25,516 KB
testcase_18 AC 53 ms
24,844 KB
testcase_19 AC 53 ms
24,920 KB
testcase_20 AC 48 ms
25,272 KB
testcase_21 AC 49 ms
25,316 KB
testcase_22 AC 52 ms
25,136 KB
testcase_23 AC 51 ms
24,984 KB
testcase_24 AC 52 ms
25,044 KB
testcase_25 AC 52 ms
25,352 KB
testcase_26 AC 52 ms
25,284 KB
testcase_27 AC 47 ms
24,872 KB
testcase_28 AC 52 ms
25,104 KB
testcase_29 AC 50 ms
25,216 KB
testcase_30 AC 51 ms
25,336 KB
testcase_31 AC 52 ms
24,860 KB
testcase_32 AC 52 ms
25,556 KB
testcase_33 AC 49 ms
25,360 KB
testcase_34 AC 47 ms
25,072 KB
testcase_35 AC 48 ms
25,296 KB
testcase_36 AC 51 ms
25,476 KB
testcase_37 AC 50 ms
24,924 KB
testcase_38 AC 50 ms
25,544 KB
testcase_39 AC 49 ms
25,112 KB
testcase_40 AC 49 ms
25,156 KB
testcase_41 AC 51 ms
25,292 KB
testcase_42 AC 51 ms
25,292 KB
testcase_43 AC 50 ms
25,416 KB
testcase_44 AC 52 ms
25,292 KB
testcase_45 AC 49 ms
25,316 KB
testcase_46 AC 52 ms
25,432 KB
testcase_47 AC 49 ms
25,008 KB
testcase_48 AC 51 ms
25,628 KB
testcase_49 AC 57 ms
25,120 KB
testcase_50 AC 50 ms
25,484 KB
testcase_51 AC 52 ms
25,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import collections
import itertools
import sys


MAX_D = 4
Status = collections.namedtuple("Status", "hit blow")
FINAL = Status(4, 0)


def compute_status(assumptive_answer, guess):
    hit = sum(int(a == c) for a, c in zip(assumptive_answer, guess))
    hit_and_blow = len(set(assumptive_answer) & set(guess))
    blow = hit_and_blow - hit
    return Status(hit, blow)


def is_possible_candidate(candidate, prev_guess, prev_status):
    return compute_status(candidate, prev_guess) == prev_status


def generate_all_candidates(d=MAX_D):
    return set(itertools.permutations(range(10), d))


def submit_guess(guess):
    print(" ".join(map(str, guess)))
    sys.stdout.flush()
    return Status(*map(int, input().split()))


def main():
    candidates = generate_all_candidates()
    while candidates:
        guess = candidates.pop()
        status = submit_guess(guess)
        if status == FINAL:
            return
        f = lambda c: is_possible_candidate(c, guess, status)
        candidates = set(filter(f, candidates))


if __name__ == '__main__':
    main()
0