結果

問題 No.1765 While Shining
ユーザー hir355hir355
提出日時 2021-11-26 22:32:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 156 ms / 2,000 ms
コード長 669 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 87,108 KB
実行使用メモリ 108,404 KB
最終ジャッジ日時 2023-09-12 05:11:36
合計ジャッジ時間 4,421 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,452 KB
testcase_01 AC 69 ms
71,416 KB
testcase_02 AC 70 ms
71,240 KB
testcase_03 AC 70 ms
71,464 KB
testcase_04 AC 70 ms
71,304 KB
testcase_05 AC 73 ms
71,056 KB
testcase_06 AC 72 ms
71,420 KB
testcase_07 AC 73 ms
71,224 KB
testcase_08 AC 74 ms
71,576 KB
testcase_09 AC 131 ms
94,260 KB
testcase_10 AC 144 ms
106,148 KB
testcase_11 AC 139 ms
99,852 KB
testcase_12 AC 143 ms
102,788 KB
testcase_13 AC 136 ms
100,036 KB
testcase_14 AC 143 ms
106,556 KB
testcase_15 AC 143 ms
106,440 KB
testcase_16 AC 148 ms
106,520 KB
testcase_17 AC 151 ms
106,796 KB
testcase_18 AC 146 ms
106,624 KB
testcase_19 AC 156 ms
106,460 KB
testcase_20 AC 147 ms
106,576 KB
testcase_21 AC 148 ms
106,468 KB
testcase_22 AC 149 ms
106,528 KB
testcase_23 AC 148 ms
106,456 KB
testcase_24 AC 120 ms
108,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
a = list(map(int, input().split()))
b = [n - 1] * n
idx = 0
for i in range(0, n, 2):
    if a[i] == 0:
        for j in range(idx, i + 1, 2):
            b[j] = i
        idx = i + 2
idx = 1
for i in range(1, n, 2):
    if a[i] == 0:
        for j in range(idx, i + 1, 2):
            b[j] = i
        idx = i + 2
c = [n - 1] * n
idx = 0
for i in range(1, n, 2):
    if a[i] == 1:
        for j in range(idx, i, 2):
            c[j] = i
        idx = i + 1
idx = 1
for i in range(0, n, 2):
    if a[i] == 1:
        for j in range(idx, i, 2):
            c[j] = i
        idx = i + 1
ans = 0
for i in range(n):
    ans += min(b[i], c[i]) - i
print(ans)
0