結果

問題 No.805 UMG
ユーザー _KingdomOfMoray_KingdomOfMoray
提出日時 2019-12-30 15:55:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,075 bytes
コンパイル時間 94 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 16,384 KB
最終ジャッジ日時 2024-04-29 11:02:15
合計ジャッジ時間 5,221 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
16,384 KB
testcase_01 AC 34 ms
10,752 KB
testcase_02 AC 31 ms
10,624 KB
testcase_03 AC 31 ms
10,624 KB
testcase_04 AC 31 ms
10,624 KB
testcase_05 AC 30 ms
10,752 KB
testcase_06 AC 33 ms
10,752 KB
testcase_07 AC 31 ms
10,624 KB
testcase_08 AC 30 ms
10,752 KB
testcase_09 AC 32 ms
10,624 KB
testcase_10 AC 31 ms
10,624 KB
testcase_11 AC 30 ms
10,624 KB
testcase_12 AC 31 ms
10,752 KB
testcase_13 AC 31 ms
10,624 KB
testcase_14 AC 31 ms
10,624 KB
testcase_15 AC 110 ms
10,624 KB
testcase_16 AC 97 ms
10,880 KB
testcase_17 AC 71 ms
10,624 KB
testcase_18 AC 146 ms
10,752 KB
testcase_19 AC 61 ms
10,624 KB
testcase_20 AC 136 ms
10,624 KB
testcase_21 AC 83 ms
10,624 KB
testcase_22 AC 94 ms
10,880 KB
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

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