結果

問題 No.2178 Payable Magic Items
ユーザー roarisroaris
提出日時 2023-01-08 16:01:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,317 ms / 4,000 ms
コード長 711 bytes
コンパイル時間 1,627 ms
コンパイル使用メモリ 86,924 KB
実行使用メモリ 84,752 KB
最終ジャッジ日時 2023-08-22 02:13:47
合計ジャッジ時間 19,622 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
75,616 KB
testcase_01 AC 68 ms
71,396 KB
testcase_02 AC 68 ms
71,520 KB
testcase_03 AC 972 ms
83,872 KB
testcase_04 AC 66 ms
71,420 KB
testcase_05 AC 1,022 ms
83,796 KB
testcase_06 AC 990 ms
83,756 KB
testcase_07 AC 68 ms
71,396 KB
testcase_08 AC 1,034 ms
83,540 KB
testcase_09 AC 264 ms
78,808 KB
testcase_10 AC 91 ms
76,980 KB
testcase_11 AC 1,212 ms
84,424 KB
testcase_12 AC 1,190 ms
84,496 KB
testcase_13 AC 1,249 ms
84,752 KB
testcase_14 AC 1,317 ms
84,648 KB
testcase_15 AC 1,203 ms
84,488 KB
testcase_16 AC 1,190 ms
84,732 KB
testcase_17 AC 1,108 ms
84,096 KB
testcase_18 AC 131 ms
78,164 KB
testcase_19 AC 314 ms
79,240 KB
testcase_20 AC 100 ms
77,952 KB
testcase_21 AC 132 ms
78,520 KB
testcase_22 AC 131 ms
78,128 KB
testcase_23 AC 99 ms
77,472 KB
testcase_24 AC 1,156 ms
84,124 KB
testcase_25 AC 1,064 ms
84,188 KB
testcase_26 AC 320 ms
79,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

def fs(l):
    res = 0
    
    for i in range(K):
        res += l[i]*pow(5, i)
    
    return res

def fl(s):
    res = []
    
    for i in range(K):
        res.append(s%5)
        s //= 5
    
    return res

N, K = map(int, input().split())
exist = [0]*pow(5, K)
cnt = [0]*pow(5, K)

for _ in range(N):
    l = list(map(int, list(input()[:-1])))
    exist[fs(l)] = 1
    cnt[fs(l)] = 1

for d in range(K):
    for S in range(pow(5, K)-1, -1, -1):
        l = fl(S)
        
        if l[d]<4:
            nS = fs(l[:d]+[l[d]+1]+l[d+1:])
            cnt[S] += cnt[nS]

ans = 0

for S in range(pow(5, K)):
    if exist[S]==1 and cnt[S]>1:
        ans += 1

print(ans)
0