結果

問題 No.2178 Payable Magic Items
ユーザー MasKoaTSMasKoaTS
提出日時 2023-11-01 19:54:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 260 ms / 4,000 ms
コード長 722 bytes
コンパイル時間 223 ms
コンパイル使用メモリ 81,872 KB
実行使用メモリ 211,956 KB
最終ジャッジ日時 2023-11-01 19:54:44
合計ジャッジ時間 4,814 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,608 KB
testcase_01 AC 37 ms
53,608 KB
testcase_02 AC 37 ms
53,608 KB
testcase_03 AC 150 ms
206,608 KB
testcase_04 AC 37 ms
53,608 KB
testcase_05 AC 85 ms
191,344 KB
testcase_06 AC 94 ms
195,616 KB
testcase_07 AC 38 ms
53,608 KB
testcase_08 AC 97 ms
195,620 KB
testcase_09 AC 61 ms
80,880 KB
testcase_10 AC 38 ms
53,608 KB
testcase_11 AC 243 ms
211,956 KB
testcase_12 AC 242 ms
211,944 KB
testcase_13 AC 251 ms
211,940 KB
testcase_14 AC 237 ms
211,944 KB
testcase_15 AC 238 ms
211,948 KB
testcase_16 AC 260 ms
211,936 KB
testcase_17 AC 187 ms
208,804 KB
testcase_18 AC 64 ms
71,264 KB
testcase_19 AC 99 ms
93,632 KB
testcase_20 AC 47 ms
62,520 KB
testcase_21 AC 57 ms
67,108 KB
testcase_22 AC 57 ms
69,160 KB
testcase_23 AC 48 ms
62,520 KB
testcase_24 AC 211 ms
210,528 KB
testcase_25 AC 177 ms
207,840 KB
testcase_26 AC 110 ms
94,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

def to_num(s):
    ret = 0
    for c in s:
        x = ord(c) - ord('0')
        ret <<= 3
        ret += x
    return ret


N, K = map(int, input().split())
st = list([to_num(input()[:-1]) for _ in [0] * N])

visited = [0] * (1 << (K * 3))
for v_start in st:
    if(visited[v_start] == 1):
        continue
    stk = [v_start]
    while(stk):
        v_now = stk.pop()
        for i in range(0, K * 3, 3):
            if(((v_now >> i) & 7) == 0):
                continue
            v_next = v_now - (1 << i)
            if(visited[v_next] == 1):
                continue
            visited[v_next] = 1
            stk.append(v_next)

ans = sum(visited[x] for x in st)
print(ans)
0