結果

問題 No.1765 While Shining
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2021-11-27 17:45:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 144 ms / 2,000 ms
コード長 610 bytes
コンパイル時間 1,517 ms
コンパイル使用メモリ 10,924 KB
実行使用メモリ 12,124 KB
最終ジャッジ日時 2023-09-12 21:02:40
合計ジャッジ時間 4,780 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,736 KB
testcase_01 AC 15 ms
7,820 KB
testcase_02 AC 14 ms
7,828 KB
testcase_03 AC 15 ms
7,740 KB
testcase_04 AC 15 ms
7,780 KB
testcase_05 AC 15 ms
7,728 KB
testcase_06 AC 15 ms
7,780 KB
testcase_07 AC 15 ms
7,868 KB
testcase_08 AC 15 ms
7,940 KB
testcase_09 AC 95 ms
10,444 KB
testcase_10 AC 131 ms
11,284 KB
testcase_11 AC 119 ms
10,884 KB
testcase_12 AC 127 ms
11,152 KB
testcase_13 AC 117 ms
11,284 KB
testcase_14 AC 140 ms
12,068 KB
testcase_15 AC 141 ms
12,116 KB
testcase_16 AC 141 ms
11,964 KB
testcase_17 AC 144 ms
11,964 KB
testcase_18 AC 140 ms
12,064 KB
testcase_19 AC 142 ms
12,076 KB
testcase_20 AC 142 ms
12,064 KB
testcase_21 AC 141 ms
12,088 KB
testcase_22 AC 141 ms
12,116 KB
testcase_23 AC 141 ms
11,936 KB
testcase_24 AC 114 ms
12,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
A = list(map(int,input().split()))
L = 0
cand = []
flg = 0
for i in range(N):
    if A[i] == 1 and L == 0:
        st = i
        L += 1
        flg = 1
    elif A[i] == 0:
        if flg == 1:
            flg = 0
            L += 1
        else:
            cand.append(L)
            L = 0
    elif A[i] == 1 and flg == 0:
        L += 1
        flg = 1
    else:
        st = i
        cand.append(L)
        L = 1
        flg = 1
cand.append(L-1)
ans = 0
for i in cand:
    if i%2 == 1:
        ans += ((i+1)//2)**2
    else:
        m = i//2
        ans += m*(m+1)
print(ans)
#print(cand)
0