結果

問題 No.355 数当てゲーム(2)
ユーザー cielciel
提出日時 2016-04-01 23:32:46
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 239 ms / 2,000 ms
コード長 1,457 bytes
コンパイル時間 147 ms
コンパイル使用メモリ 77,748 KB
実行使用メモリ 114,976 KB
平均クエリ数 5.35
最終ジャッジ日時 2023-09-23 23:31:38
合計ジャッジ時間 13,461 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 202 ms
114,636 KB
testcase_01 AC 212 ms
113,520 KB
testcase_02 AC 211 ms
114,548 KB
testcase_03 AC 198 ms
114,196 KB
testcase_04 AC 205 ms
114,040 KB
testcase_05 AC 211 ms
114,088 KB
testcase_06 AC 205 ms
114,348 KB
testcase_07 AC 196 ms
114,220 KB
testcase_08 AC 197 ms
114,208 KB
testcase_09 AC 197 ms
114,208 KB
testcase_10 AC 208 ms
113,996 KB
testcase_11 AC 203 ms
114,016 KB
testcase_12 AC 203 ms
114,320 KB
testcase_13 AC 195 ms
114,352 KB
testcase_14 AC 191 ms
113,632 KB
testcase_15 AC 202 ms
113,584 KB
testcase_16 AC 215 ms
114,344 KB
testcase_17 AC 206 ms
114,196 KB
testcase_18 AC 193 ms
113,956 KB
testcase_19 AC 209 ms
114,576 KB
testcase_20 AC 199 ms
114,276 KB
testcase_21 AC 239 ms
114,020 KB
testcase_22 AC 200 ms
114,228 KB
testcase_23 AC 216 ms
114,680 KB
testcase_24 AC 201 ms
114,020 KB
testcase_25 AC 198 ms
114,188 KB
testcase_26 AC 209 ms
114,144 KB
testcase_27 AC 214 ms
114,580 KB
testcase_28 AC 208 ms
114,288 KB
testcase_29 AC 202 ms
114,096 KB
testcase_30 AC 211 ms
114,728 KB
testcase_31 AC 203 ms
113,752 KB
testcase_32 AC 196 ms
113,380 KB
testcase_33 AC 210 ms
114,172 KB
testcase_34 AC 193 ms
114,192 KB
testcase_35 AC 159 ms
109,408 KB
testcase_36 AC 206 ms
114,048 KB
testcase_37 AC 195 ms
113,588 KB
testcase_38 AC 210 ms
114,412 KB
testcase_39 AC 202 ms
114,928 KB
testcase_40 AC 196 ms
113,884 KB
testcase_41 AC 206 ms
114,456 KB
testcase_42 AC 207 ms
114,976 KB
testcase_43 AC 203 ms
114,356 KB
testcase_44 AC 206 ms
113,732 KB
testcase_45 AC 191 ms
114,196 KB
testcase_46 AC 197 ms
114,116 KB
testcase_47 AC 206 ms
114,536 KB
testcase_48 AC 198 ms
113,800 KB
testcase_49 AC 207 ms
114,936 KB
testcase_50 AC 203 ms
113,880 KB
testcase_51 AC 191 ms
114,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python
#coding:utf-8
from collections import Counter
import itertools,random

digits=4
#mode='mastermind'
mode='hitandblow'

def hit_and_blow(a,b):
	hit=sum(a[i]==b[i] for i in range(digits))
	if mode=='mastermind':
		#mastermind allows duplication (slow)
		ca=Counter(a)
		cb=Counter(b)
		blow=sum(min(0 if k not in cb else cb[k],v) for k,v in ca.items())
	else:
		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():
	if mode=='mastermind':
		return list(''.join(e) for e in itertools.product(iter('123456'),repeat=digits))
	else:
		return list(''.join(e) for e in itertools.permutations(iter('0123456789'),digits))

def checkio(data):
	global lst
	if len(data)==0:
		lst=genlist()
		if mode=='mastermind': return '1122'
		else: return '0123'
	last=data[-1].split()
	hit=int(last[1][0])
	blow=int(last[1][2])
	last=last[0]
	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] # こちらの評価関数を使うとクエリ数を削減できるがTLE
	return random.choice(lst)

if __name__ == '__main__':
	import sys
	if sys.version_info[0]>=3: raw_input=input
	q=[]
	while True:
		s=checkio(q)
		print(' '.join(s))
		sys.stdout.flush()
		t=raw_input().strip()
		if t=='4 0':break
		q.append(s+' '+'H'.join(t.split()))
0