結果

問題 No.805 UMG
ユーザー _KingdomOfMoray_KingdomOfMoray
提出日時 2019-12-30 15:56:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,032 ms / 2,000 ms
コード長 1,075 bytes
コンパイル時間 138 ms
コンパイル使用メモリ 82,340 KB
実行使用メモリ 75,776 KB
最終ジャッジ日時 2024-04-29 11:02:35
合計ジャッジ時間 7,004 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
51,840 KB
testcase_01 AC 40 ms
51,840 KB
testcase_02 AC 38 ms
51,712 KB
testcase_03 AC 36 ms
51,840 KB
testcase_04 AC 37 ms
51,712 KB
testcase_05 AC 37 ms
51,840 KB
testcase_06 AC 37 ms
51,968 KB
testcase_07 AC 36 ms
51,712 KB
testcase_08 AC 38 ms
52,096 KB
testcase_09 AC 37 ms
51,712 KB
testcase_10 AC 36 ms
51,456 KB
testcase_11 AC 35 ms
51,328 KB
testcase_12 AC 35 ms
51,968 KB
testcase_13 AC 36 ms
51,712 KB
testcase_14 AC 36 ms
51,712 KB
testcase_15 AC 52 ms
61,440 KB
testcase_16 AC 47 ms
60,160 KB
testcase_17 AC 46 ms
59,904 KB
testcase_18 AC 54 ms
61,696 KB
testcase_19 AC 46 ms
59,648 KB
testcase_20 AC 54 ms
61,824 KB
testcase_21 AC 47 ms
59,648 KB
testcase_22 AC 50 ms
59,904 KB
testcase_23 AC 1,022 ms
75,776 KB
testcase_24 AC 979 ms
75,520 KB
testcase_25 AC 1,031 ms
75,648 KB
testcase_26 AC 1,032 ms
75,520 KB
testcase_27 AC 1,024 ms
75,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def min(a, b):
    return a if a <= b else b

n = int(input())
s = input()
s_list = list(s)

num_M = s_list.count('M')
checked_M = 0
count = 0

while checked_M != num_M:
    M_index = s_list.index('M')
    distance = min(M_index - 0, (n - 1) - M_index)
    ss_list = s_list[M_index - distance : M_index + distance + 1]
#     print('ss_list before: {}'.format(ss_list))
    num_U = ss_list.count('U')
    M_index_ss = ss_list.index('M')
    for i in range(num_U):
        U_index = ss_list.index('U')
        if U_index > M_index_ss:
            break
        else:
            ss_list[U_index] = 'x'
            distance_ss = M_index_ss - U_index
#             print('M_index_ss: {}'.format(M_index_ss))
#             print('U_index: {}'.format(U_index))
#             print('distance_ss: {}'.format(distance_ss))
            if ss_list[M_index_ss + distance_ss] == 'G':
                count += 1
#     print('ss_list after: {}'.format(ss_list))
#     print('count: {}'.format(count))
    # after founding 'umg'
    s_list[M_index] = 'x'
    checked_M += 1
    
print(count)
0