結果

問題 No.220 世界のなんとか2
ユーザー shobonvipshobonvip
提出日時 2022-07-29 20:56:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 78 ms / 1,000 ms
コード長 668 bytes
コンパイル時間 610 ms
コンパイル使用メモリ 87,000 KB
実行使用メモリ 71,508 KB
最終ジャッジ日時 2023-09-26 17:52:19
合計ジャッジ時間 3,147 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,320 KB
testcase_01 AC 75 ms
71,508 KB
testcase_02 AC 78 ms
70,984 KB
testcase_03 AC 74 ms
71,144 KB
testcase_04 AC 71 ms
70,980 KB
testcase_05 AC 72 ms
71,192 KB
testcase_06 AC 73 ms
71,144 KB
testcase_07 AC 75 ms
71,144 KB
testcase_08 AC 73 ms
71,176 KB
testcase_09 AC 74 ms
71,228 KB
testcase_10 AC 74 ms
71,184 KB
testcase_11 AC 75 ms
71,360 KB
testcase_12 AC 73 ms
71,172 KB
testcase_13 AC 72 ms
71,192 KB
testcase_14 AC 74 ms
71,120 KB
testcase_15 AC 74 ms
71,300 KB
testcase_16 AC 72 ms
71,076 KB
testcase_17 AC 74 ms
71,248 KB
testcase_18 AC 73 ms
71,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 桁DP
# dp[i][j] : iの倍数であり, jを含む

p = int(input())
unhav = [0] * 3
hav = [0] * 3
nowstate = 0
for num in range(p+1):
	nunhav = [0] * 3
	nhav = [0] * 3
	
	#継続
	for i in range(0, 10):
		for j in range(3):
			if i == 3:
				nhav[(i+j)%3] += unhav[j] + hav[j]
			else:
				nunhav[(i+j)%3] += unhav[j]
				nhav[(i+j)%3] += hav[j]
	
	#新規
	if num > 0:
		for i in range(1, 10):
			if i == 3:
				nhav[i%3] += 1
			else:
				nunhav[i%3] += 1
	
	for i in range(3):
		hav[i] = nhav[i]
		unhav[i] = nunhav[i]
	
	nowstate = nowstate * 10
	
	if num == 0:
		nowstate += 1
	
	nowstate %= 3

unhav[nowstate] += 1

print(unhav[0] + hav[0] + hav[1] + hav[2])
0