結果

問題 No.1765 While Shining
ユーザー ygd.ygd.
提出日時 2021-12-02 00:42:06
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 1,285 bytes
コンパイル時間 262 ms
コンパイル使用メモリ 10,912 KB
実行使用メモリ 19,620 KB
最終ジャッジ日時 2023-09-18 10:05:58
合計ジャッジ時間 3,430 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,788 KB
testcase_01 AC 16 ms
7,920 KB
testcase_02 AC 16 ms
7,836 KB
testcase_03 AC 17 ms
7,812 KB
testcase_04 AC 16 ms
7,808 KB
testcase_05 AC 16 ms
7,836 KB
testcase_06 AC 16 ms
7,824 KB
testcase_07 AC 16 ms
7,824 KB
testcase_08 AC 17 ms
7,784 KB
testcase_09 AC 81 ms
15,368 KB
testcase_10 AC 120 ms
18,560 KB
testcase_11 AC 98 ms
17,300 KB
testcase_12 AC 117 ms
18,276 KB
testcase_13 AC 97 ms
17,088 KB
testcase_14 AC 128 ms
19,588 KB
testcase_15 AC 127 ms
19,620 KB
testcase_16 AC 127 ms
19,616 KB
testcase_17 AC 126 ms
19,556 KB
testcase_18 AC 128 ms
19,524 KB
testcase_19 AC 130 ms
19,548 KB
testcase_20 AC 128 ms
19,552 KB
testcase_21 AC 128 ms
19,556 KB
testcase_22 AC 128 ms
19,548 KB
testcase_23 AC 125 ms
19,528 KB
testcase_24 AC 69 ms
11,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#input = sys.stdin.readline #文字列につけてはダメ
input = sys.stdin.buffer.readline #文字列につけてはダメ
#sys.setrecursionlimit(1000000)
#import bisect
#import itertools
#import random
#from heapq import heapify, heappop, heappush
#from collections import defaultdict
#from collections import deque
#import copy

#かなり実装難しい。★2ではないでしょ。

def main():
    N = int(input())
    A = [0] + list(map(int,input().split()))
    B = []
    ans = 0
    temp = []
    for i in range(1,N+1):
        if A[i] == 0:
            if A[i-1] == 1:
                temp.append(A[i])
            else:
                B.append(temp)
                temp = []
        else:
            if A[i-1] == 0:
                temp.append(A[i])
            else:
                B.append(temp)
                temp = [A[i]]
    if temp:
        if temp[-1] == 0:
            ans -= len(temp)//2
        else:
            ans -= (len(temp)+1)//2
    B.append(temp)
    #print(ans)

    for i in range(len(B)):
        if len(B[i])%2 == 1:
            x = (len(B[i])+1)//2
            ans += x**2
        else:
            x = len(B[i])//2
            ans += (1+x)*x
        #print(ans)
    print(ans)


        


if __name__ == '__main__':
    main()
0