結果

問題 No.1765 While Shining
ユーザー playerplayer
提出日時 2024-01-15 02:02:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 743 bytes
コンパイル時間 358 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 114,088 KB
最終ジャッジ日時 2024-01-15 02:02:45
合計ジャッジ時間 4,266 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 34 ms
53,460 KB
testcase_02 AC 35 ms
53,460 KB
testcase_03 AC 36 ms
53,460 KB
testcase_04 AC 35 ms
53,460 KB
testcase_05 AC 37 ms
53,460 KB
testcase_06 AC 35 ms
53,460 KB
testcase_07 AC 34 ms
53,460 KB
testcase_08 AC 36 ms
53,460 KB
testcase_09 AC 90 ms
101,760 KB
testcase_10 AC 101 ms
109,444 KB
testcase_11 AC 96 ms
104,576 KB
testcase_12 AC 95 ms
106,368 KB
testcase_13 AC 91 ms
105,168 KB
testcase_14 AC 104 ms
108,108 KB
testcase_15 AC 96 ms
108,108 KB
testcase_16 AC 98 ms
108,108 KB
testcase_17 AC 97 ms
108,108 KB
testcase_18 AC 96 ms
108,736 KB
testcase_19 AC 103 ms
108,108 KB
testcase_20 AC 95 ms
108,108 KB
testcase_21 AC 96 ms
108,736 KB
testcase_22 AC 98 ms
108,736 KB
testcase_23 AC 96 ms
108,108 KB
testcase_24 AC 88 ms
114,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
a = list(map(int, input().split()))

lis = []
tmp = []
for i in range(n):
    if i == 0:
        former = a[0]
        tmp.append(a[0])
    else:
        if former != a[i]:
            tmp.append(a[i])
            former = a[i]
        else:
            lis.append(tmp)
            tmp = []
            tmp.append(a[i])
            former = a[i]

if tmp != []:
    lis.append(tmp)
ans = 0
cnt = 0
for i in range(len(lis)):
    if i != len(lis) - 1:
        for j in range(len(lis[i])):
            if a[cnt] == 1:
                ans += len(lis[i]) - j
            cnt += 1
    else:
        for j in range(len(lis[i])):
            if a[cnt] == 1:
                ans += len(lis[i]) - (j + 1)
            cnt += 1

print(ans)
0