結果
問題 | No.1435 Mmm...... |
ユーザー | shotoyoo |
提出日時 | 2021-03-20 00:10:43 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,736 ms / 2,000 ms |
コード長 | 2,204 bytes |
コンパイル時間 | 182 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 113,072 KB |
最終ジャッジ日時 | 2024-04-29 20:11:12 |
合計ジャッジ時間 | 29,276 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
53,120 KB |
testcase_01 | AC | 45 ms
52,608 KB |
testcase_02 | AC | 44 ms
52,480 KB |
testcase_03 | AC | 44 ms
52,992 KB |
testcase_04 | AC | 43 ms
53,120 KB |
testcase_05 | AC | 43 ms
52,608 KB |
testcase_06 | AC | 995 ms
96,512 KB |
testcase_07 | AC | 1,298 ms
98,100 KB |
testcase_08 | AC | 1,612 ms
104,192 KB |
testcase_09 | AC | 1,283 ms
101,504 KB |
testcase_10 | AC | 1,214 ms
97,904 KB |
testcase_11 | AC | 1,162 ms
98,308 KB |
testcase_12 | AC | 1,406 ms
97,920 KB |
testcase_13 | AC | 1,029 ms
96,384 KB |
testcase_14 | AC | 900 ms
90,496 KB |
testcase_15 | AC | 1,736 ms
104,704 KB |
testcase_16 | AC | 1,260 ms
98,672 KB |
testcase_17 | AC | 958 ms
91,776 KB |
testcase_18 | AC | 1,517 ms
104,540 KB |
testcase_19 | AC | 1,060 ms
96,896 KB |
testcase_20 | AC | 1,358 ms
101,120 KB |
testcase_21 | AC | 411 ms
113,072 KB |
testcase_22 | AC | 565 ms
106,624 KB |
testcase_23 | AC | 1,297 ms
101,488 KB |
testcase_24 | AC | 1,706 ms
101,536 KB |
testcase_25 | AC | 1,468 ms
101,264 KB |
testcase_26 | AC | 1,662 ms
101,660 KB |
testcase_27 | AC | 1,704 ms
102,316 KB |
ソースコード
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(2*10**5+10) write = lambda x: sys.stdout.write(x+"\n") debug = lambda x: sys.stderr.write(x+"\n") # 二分探索木の代わり BST HST # 存在しない要素に対するremoveはこないことを仮定している """↓より少し遅い(?)が、同一要素を複数入れた場合に数を保持するd """ from heapq import heappop as hpp, heappush as hp # 二分探索木の代わり BST HST # 存在しない要素に対するremoveはこないことを仮定している """↓より少し遅い(?)が、同一要素を複数入れた場合に数を保持するd """ from heapq import heappop as hpp, heappush as hp class HST: def __init__(self, s=1): self._h = [] self._q = [] self._s = s def push(self, v): hp(self._h, self._s*v) def remove(self, v): hp(self._q, self._s*v) def top(self): while self._q and self._q[0]==self._h[0]: hpp(self._q) hpp(self._h) if not self._h: res = None else: res = self._s*self._h[0] return res def second(self): v = self.top() if v is None: return None self.remove(v) v2 = self.top() if v2 is not None: v2 *= self._s self.push(v) return v2 n = int(input()) a = list(map(int, input().split())) from heapq import heappop as hpp, heappush as hp h = HST() H = HST() j = 0 ans = 0 ans0 = 0 for i in range(n): mi = 0 while j<n: if j-i>=3: m0 = h.top() m1 = h.second() M = H.top() if m0+m1>=-M: pass else: break h.push(a[j]) H.push(-a[j]) j += 1 m0 = h.top() m1 = h.second() M = H.top() if m1 is not None and m0+m1<-M: ans += (j-i-2) else: ans += (j-i-1) h.remove(a[i]) H.remove(-a[i]) # l = sorted(a[i:j]) # if l[0]+l[1]<l[-1]: # ans0 += (j-i-2) # else: # ans0 += (j-i-1) # if ans!=ans0: # print(m0,m1,-M) # assert 0 print(ans)