結果

問題 No.1765 While Shining
ユーザー irumo8202irumo8202
提出日時 2022-01-27 18:16:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 206 ms / 2,000 ms
コード長 676 bytes
コンパイル時間 2,098 ms
コンパイル使用メモリ 86,528 KB
実行使用メモリ 105,296 KB
最終ジャッジ日時 2023-08-26 19:28:31
合計ジャッジ時間 8,157 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
79,356 KB
testcase_01 AC 138 ms
79,304 KB
testcase_02 AC 134 ms
79,380 KB
testcase_03 AC 137 ms
79,412 KB
testcase_04 AC 135 ms
79,792 KB
testcase_05 AC 139 ms
79,440 KB
testcase_06 AC 136 ms
79,564 KB
testcase_07 AC 136 ms
79,520 KB
testcase_08 AC 136 ms
79,672 KB
testcase_09 AC 193 ms
92,636 KB
testcase_10 AC 194 ms
105,152 KB
testcase_11 AC 187 ms
98,056 KB
testcase_12 AC 189 ms
101,064 KB
testcase_13 AC 183 ms
98,036 KB
testcase_14 AC 198 ms
105,116 KB
testcase_15 AC 198 ms
105,276 KB
testcase_16 AC 201 ms
105,172 KB
testcase_17 AC 198 ms
104,916 KB
testcase_18 AC 197 ms
105,120 KB
testcase_19 AC 206 ms
104,932 KB
testcase_20 AC 204 ms
105,216 KB
testcase_21 AC 200 ms
104,964 KB
testcase_22 AC 193 ms
104,952 KB
testcase_23 AC 196 ms
105,296 KB
testcase_24 AC 192 ms
105,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
A = list(map(int, input().split()))

import re


def get_idxs(string, word):
    idxs = []

    for res in re.finditer(word, string):
        idxs.append(res.span()[0])

    return idxs


inds = get_idxs("".join(map(str, A)), "1")

ans = [0] * len(inds)
for i in range(len(inds))[::-1]:
    if i == len(inds) - 1:
        if inds[i] == N - 1:
            continue
        elif inds[i] == N - 2:
            ans[i] = 1
        else:
            ans[i] = 2
    else:
        if inds[i] + 2 == inds[i + 1]:
            ans[i] += 2 + ans[i + 1]
        elif inds[i] + 1 == inds[i + 1]:
            ans[i] = 1
        else:
            ans[i] = 2

print(sum(ans))
0