結果

問題 No.1765 While Shining
コンテスト
ユーザー player
提出日時 2024-01-15 02:02:41
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 743 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 696 ms
コンパイル使用メモリ 85,632 KB
実行使用メモリ 122,752 KB
最終ジャッジ日時 2026-04-14 19:11:40
合計ジャッジ時間 3,930 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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