結果

問題 No.355 数当てゲーム(2)
ユーザー cielciel
提出日時 2016-04-01 23:19:20
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 1,827 ms / 2,000 ms
コード長 1,368 bytes
コンパイル時間 2,187 ms
コンパイル使用メモリ 77,328 KB
実行使用メモリ 117,956 KB
平均クエリ数 5.31
最終ジャッジ日時 2023-09-23 09:32:00
合計ジャッジ時間 57,258 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 310 ms
115,532 KB
testcase_01 AC 1,399 ms
116,364 KB
testcase_02 AC 1,744 ms
116,524 KB
testcase_03 AC 634 ms
115,444 KB
testcase_04 AC 1,363 ms
117,160 KB
testcase_05 AC 642 ms
115,536 KB
testcase_06 AC 1,706 ms
117,956 KB
testcase_07 AC 378 ms
114,888 KB
testcase_08 AC 375 ms
115,188 KB
testcase_09 AC 336 ms
116,312 KB
testcase_10 AC 1,749 ms
117,188 KB
testcase_11 AC 646 ms
114,960 KB
testcase_12 AC 658 ms
115,052 KB
testcase_13 AC 619 ms
114,672 KB
testcase_14 AC 252 ms
114,748 KB
testcase_15 AC 360 ms
114,896 KB
testcase_16 AC 1,735 ms
117,508 KB
testcase_17 AC 455 ms
115,100 KB
testcase_18 AC 252 ms
114,648 KB
testcase_19 AC 1,367 ms
116,172 KB
testcase_20 AC 458 ms
115,368 KB
testcase_21 AC 370 ms
115,144 KB
testcase_22 AC 447 ms
115,516 KB
testcase_23 AC 1,801 ms
116,940 KB
testcase_24 AC 347 ms
114,804 KB
testcase_25 AC 647 ms
114,640 KB
testcase_26 AC 1,719 ms
117,320 KB
testcase_27 AC 1,814 ms
117,484 KB
testcase_28 AC 1,816 ms
117,056 KB
testcase_29 AC 646 ms
115,552 KB
testcase_30 AC 1,436 ms
116,556 KB
testcase_31 AC 1,370 ms
115,812 KB
testcase_32 AC 380 ms
115,380 KB
testcase_33 AC 1,818 ms
117,340 KB
testcase_34 AC 666 ms
115,292 KB
testcase_35 AC 181 ms
110,028 KB
testcase_36 AC 1,397 ms
116,580 KB
testcase_37 AC 456 ms
115,500 KB
testcase_38 AC 1,816 ms
116,672 KB
testcase_39 AC 1,815 ms
117,276 KB
testcase_40 AC 459 ms
115,996 KB
testcase_41 AC 1,793 ms
116,704 KB
testcase_42 AC 1,697 ms
116,644 KB
testcase_43 AC 1,827 ms
116,684 KB
testcase_44 AC 627 ms
115,032 KB
testcase_45 AC 283 ms
114,624 KB
testcase_46 AC 331 ms
115,748 KB
testcase_47 AC 1,678 ms
117,096 KB
testcase_48 AC 667 ms
115,164 KB
testcase_49 AC 1,704 ms
116,508 KB
testcase_50 AC 1,458 ms
116,488 KB
testcase_51 AC 230 ms
113,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python
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]
	#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