結果

問題 No.2593 Reorder and Mod 120
ユーザー ntudantuda
提出日時 2023-12-23 11:59:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 526 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 76,320 KB
最終ジャッジ日時 2023-12-23 11:59:40
合計ジャッジ時間 2,889 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,588 KB
testcase_01 AC 40 ms
53,460 KB
testcase_02 AC 40 ms
55,740 KB
testcase_03 AC 42 ms
58,812 KB
testcase_04 AC 43 ms
58,812 KB
testcase_05 AC 40 ms
53,588 KB
testcase_06 AC 43 ms
58,812 KB
testcase_07 AC 39 ms
53,460 KB
testcase_08 AC 39 ms
53,460 KB
testcase_09 AC 39 ms
53,460 KB
testcase_10 AC 39 ms
53,460 KB
testcase_11 AC 52 ms
68,532 KB
testcase_12 AC 53 ms
70,580 KB
testcase_13 AC 63 ms
76,292 KB
testcase_14 AC 54 ms
72,628 KB
testcase_15 AC 69 ms
76,216 KB
testcase_16 AC 53 ms
70,580 KB
testcase_17 AC 55 ms
72,628 KB
testcase_18 AC 54 ms
72,628 KB
testcase_19 AC 63 ms
76,268 KB
testcase_20 AC 64 ms
76,320 KB
testcase_21 AC 64 ms
76,320 KB
testcase_22 AC 64 ms
76,320 KB
testcase_23 AC 63 ms
76,320 KB
testcase_24 AC 55 ms
73,760 KB
testcase_25 AC 55 ms
73,760 KB
testcase_26 AC 54 ms
73,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from itertools import permutations

N = int(input())
S = input()

if N == 1:
    print(1)
    exit()
if N == 2:
    if S[0] == S[1]:
        print(1)
    else:
        print(2)
    exit()

sum0 = 0
dic = defaultdict(int)
for s in S:
    s = int(s)
    dic[s] += 1
    sum0 += s
X = []
for k, v in dic.items():
    X += [k] * (min(3, v))

Y = set()
for a, b, c in set(permutations(X, 3)):
    y = a * 100 + b * 10 + c + 40 * ((sum0 - a - b - c) % 3)
    y %= 120
    Y.add(y)

print(len(Y))
0