結果

問題 No.355 数当てゲーム(2)
ユーザー cielciel
提出日時 2016-04-01 23:31:00
言語 PyPy2
(7.3.13)
結果
AC  
実行時間 216 ms / 2,000 ms
コード長 932 bytes
コンパイル時間 566 ms
コンパイル使用メモリ 77,596 KB
実行使用メモリ 115,192 KB
平均クエリ数 5.31
最終ジャッジ日時 2023-09-23 23:30:56
合計ジャッジ時間 13,458 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 203 ms
114,112 KB
testcase_01 AC 207 ms
114,040 KB
testcase_02 AC 208 ms
113,868 KB
testcase_03 AC 195 ms
113,964 KB
testcase_04 AC 209 ms
114,292 KB
testcase_05 AC 198 ms
114,080 KB
testcase_06 AC 208 ms
114,536 KB
testcase_07 AC 198 ms
113,912 KB
testcase_08 AC 200 ms
114,072 KB
testcase_09 AC 196 ms
113,980 KB
testcase_10 AC 208 ms
114,628 KB
testcase_11 AC 202 ms
113,648 KB
testcase_12 AC 200 ms
113,764 KB
testcase_13 AC 197 ms
114,324 KB
testcase_14 AC 192 ms
114,156 KB
testcase_15 AC 198 ms
113,636 KB
testcase_16 AC 210 ms
114,288 KB
testcase_17 AC 193 ms
113,720 KB
testcase_18 AC 197 ms
113,848 KB
testcase_19 AC 212 ms
114,292 KB
testcase_20 AC 199 ms
113,492 KB
testcase_21 AC 202 ms
113,784 KB
testcase_22 AC 199 ms
114,008 KB
testcase_23 AC 213 ms
114,364 KB
testcase_24 AC 197 ms
113,972 KB
testcase_25 AC 203 ms
114,548 KB
testcase_26 AC 205 ms
114,400 KB
testcase_27 AC 210 ms
114,296 KB
testcase_28 AC 202 ms
114,628 KB
testcase_29 AC 200 ms
113,836 KB
testcase_30 AC 204 ms
114,428 KB
testcase_31 AC 212 ms
115,028 KB
testcase_32 AC 202 ms
113,744 KB
testcase_33 AC 210 ms
114,196 KB
testcase_34 AC 199 ms
113,624 KB
testcase_35 AC 160 ms
109,528 KB
testcase_36 AC 209 ms
115,192 KB
testcase_37 AC 196 ms
113,844 KB
testcase_38 AC 216 ms
113,860 KB
testcase_39 AC 205 ms
114,396 KB
testcase_40 AC 202 ms
113,752 KB
testcase_41 AC 211 ms
114,872 KB
testcase_42 AC 210 ms
114,400 KB
testcase_43 AC 211 ms
114,436 KB
testcase_44 AC 203 ms
113,968 KB
testcase_45 AC 193 ms
113,836 KB
testcase_46 AC 200 ms
113,380 KB
testcase_47 AC 209 ms
114,608 KB
testcase_48 AC 200 ms
114,180 KB
testcase_49 AC 214 ms
115,104 KB
testcase_50 AC 210 ms
114,300 KB
testcase_51 AC 191 ms
114,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python
from collections import Counter
import itertools,random

digits=4

def hit_and_blow(a,b):
	hit=sum(a[i]==b[i] for i in range(digits))
	blow=len(a)+len(b)-len(set(iter(a+b)))
	return (hit,blow-hit)

def minimax(e):
	h={}
	for f in lst:
		x=hit_and_blow(e,f)
		if x not in h: h[x]=0
		h[x]+=1
	return (max(h.values()),e)

def genlist():
	return list(''.join(e) for e in itertools.permutations(iter('0123456789'),digits))

def checkio(last,hit,blow):
	global lst
	if last is None:
		lst=genlist()
		return '0123'
	for i in range(len(lst)-1,-1,-1):
		if hit_and_blow(lst[i],last)!=(hit,blow): lst.pop(i)
	#return min(minimax(e) for e in lst)[1]
	return random.choice(lst)

if __name__ == '__main__':
	import sys
	if sys.version_info[0]>=3: raw_input=input
	q=None
	hit=blow=0
	while True:
		s=checkio(q,hit,blow)
		print(' '.join(s))
		sys.stdout.flush()
		hit,blow=map(int,raw_input().split())
		if hit==4:break
		q=s
0