結果

問題 No.2178 Payable Magic Items
ユーザー HydruHydru
提出日時 2023-01-06 23:01:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,353 ms / 4,000 ms
コード長 1,057 bytes
コンパイル時間 364 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 145,724 KB
最終ジャッジ日時 2024-05-08 13:38:43
合計ジャッジ時間 9,916 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,224 KB
testcase_01 AC 40 ms
52,608 KB
testcase_02 AC 39 ms
52,096 KB
testcase_03 AC 39 ms
51,968 KB
testcase_04 AC 38 ms
52,224 KB
testcase_05 AC 39 ms
52,736 KB
testcase_06 AC 57 ms
73,472 KB
testcase_07 AC 39 ms
52,224 KB
testcase_08 AC 72 ms
76,032 KB
testcase_09 AC 66 ms
75,904 KB
testcase_10 AC 39 ms
52,608 KB
testcase_11 AC 1,002 ms
131,980 KB
testcase_12 AC 387 ms
131,572 KB
testcase_13 AC 1,353 ms
145,724 KB
testcase_14 AC 381 ms
131,072 KB
testcase_15 AC 378 ms
130,944 KB
testcase_16 AC 377 ms
131,200 KB
testcase_17 AC 1,052 ms
117,692 KB
testcase_18 AC 97 ms
77,180 KB
testcase_19 AC 144 ms
88,576 KB
testcase_20 AC 52 ms
61,824 KB
testcase_21 AC 74 ms
74,112 KB
testcase_22 AC 81 ms
77,056 KB
testcase_23 AC 54 ms
63,360 KB
testcase_24 AC 1,226 ms
133,380 KB
testcase_25 AC 981 ms
110,408 KB
testcase_26 AC 169 ms
93,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,k=map(int,input().split())
if n==1 or k==1:
    print(n-1)
    exit()

S=[input() for _ in range(n)]
X=[list(int(s) for s in S[i]) for i in range(n)]

A=[sum(x) for x in X]
entry_set=set(S)


max_A=max(A)
if max_A==4*k:
    print(n-1)
    exit()

remove_set=set()
for i in range(n):
    if A[i]==max_A:
        entry_set.remove(S[i])
        for j in range(k):
            if X[i][j]==0:
                continue
            remove_set.add("".join([str(X[i][l]-1) if l==j else str(X[i][l]) for l in range(k)]))
            

num=max_A-1
ans=0
while(entry_set):
    for i in range(n):
        if A[i]==num:
            if S[i] in remove_set:
                ans+=1
            else:
                remove_set.add(S[i])
            entry_set.remove(S[i])
    _remove_set=set()
    for r in remove_set:
        for j in range(k):
            if r[j]=="0":
                continue
            R=list(r)
            R[j]=str(int(R[j])-1)
            _remove_set.add("".join(R))
    remove_set=_remove_set
    num-=1
    if num==-1:
        break

print(ans)
0