結果
問題 |
No.1765 While Shining
|
ユーザー |
![]() |
提出日時 | 2021-12-02 00:37:22 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,320 bytes |
コンパイル時間 | 134 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 22,268 KB |
最終ジャッジ日時 | 2024-07-05 01:44:48 |
合計ジャッジ時間 | 4,225 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 WA * 3 |
ソースコード
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 class UnionFind(object): def __init__(self, n=1): self.par = [i for i in range(n)] self.rank = [0 for _ in range(n)] self.size = [1 for _ in range(n)] def find(self, x): """ x が属するグループを探索して親を出す。 """ if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def union(self, x, y): """ x と y のグループを結合 """ x = self.find(x) y = self.find(y) if x != y: if self.rank[x] < self.rank[y]: x, y = y, x if self.rank[x] == self.rank[y]: self.rank[x] += 1 self.par[y] = x self.size[x] += self.size[y] def is_same(self, x, y): """ x と y が同じグループか否か """ return self.find(x) == self.find(y) def get_size(self, x): """ x が属するグループの要素数 """ x = self.find(x) return self.size[x] def main(): N = int(input()) A = [0] + list(map(int,input().split())) B = [] 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]] B.append(temp) #print(B) ans = 0 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) if A[-1] == 0: print(ans) else: v = (len(B[-1])+1)//2 ans -= v print(ans) if __name__ == '__main__': main()