結果

問題 No.805 UMG
ユーザー kbyskbys
提出日時 2020-03-30 00:09:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 226 ms / 2,000 ms
コード長 620 bytes
コンパイル時間 204 ms
コンパイル使用メモリ 81,664 KB
実行使用メモリ 67,840 KB
最終ジャッジ日時 2024-04-29 11:05:24
合計ジャッジ時間 3,316 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
53,376 KB
testcase_01 AC 46 ms
53,376 KB
testcase_02 AC 45 ms
53,632 KB
testcase_03 AC 46 ms
53,632 KB
testcase_04 AC 46 ms
53,376 KB
testcase_05 AC 47 ms
53,248 KB
testcase_06 AC 47 ms
53,376 KB
testcase_07 AC 46 ms
53,376 KB
testcase_08 AC 50 ms
59,264 KB
testcase_09 AC 45 ms
53,504 KB
testcase_10 AC 45 ms
53,504 KB
testcase_11 AC 46 ms
53,376 KB
testcase_12 AC 46 ms
53,248 KB
testcase_13 AC 50 ms
59,392 KB
testcase_14 AC 47 ms
53,504 KB
testcase_15 AC 60 ms
61,440 KB
testcase_16 AC 59 ms
61,312 KB
testcase_17 AC 58 ms
61,312 KB
testcase_18 AC 62 ms
61,952 KB
testcase_19 AC 59 ms
61,952 KB
testcase_20 AC 60 ms
61,568 KB
testcase_21 AC 59 ms
61,312 KB
testcase_22 AC 58 ms
61,568 KB
testcase_23 AC 198 ms
67,584 KB
testcase_24 AC 197 ms
67,584 KB
testcase_25 AC 200 ms
67,840 KB
testcase_26 AC 226 ms
67,712 KB
testcase_27 AC 200 ms
67,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
N = int(input())
S = input()

U = deque([])
M = deque([])
G = deque([])

for i,s in enumerate(S):
    if s == "U":
        U.append(i)
    elif s == "M":
        M.append(i)
    else:
        G.append(i)

U,M,G = set(U),set(M),set(G)
ans = 0

flag = True
try:
    minU = min(U)
    maxM = max(M)
    maxG = max(G)
except ValueError:
    flag = False
    print(0)

step = 1
if flag:
    while True:
        if minU+step > maxM or minU+2*step > maxG:
            break
        for n in U:
            if n+step in M and n+2*step in G:
                ans += 1
        step += 1
    print(ans)
0