結果
問題 | No.1965 Heavier |
ユーザー | chineristAC |
提出日時 | 2022-06-03 23:02:11 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 508 ms / 2,000 ms |
コード長 | 1,610 bytes |
コンパイル時間 | 238 ms |
コンパイル使用メモリ | 82,216 KB |
実行使用メモリ | 145,228 KB |
最終ジャッジ日時 | 2024-09-21 03:12:24 |
合計ジャッジ時間 | 9,465 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
57,464 KB |
testcase_01 | AC | 44 ms
56,096 KB |
testcase_02 | AC | 44 ms
56,976 KB |
testcase_03 | AC | 44 ms
56,284 KB |
testcase_04 | AC | 45 ms
56,464 KB |
testcase_05 | AC | 43 ms
56,900 KB |
testcase_06 | AC | 470 ms
135,316 KB |
testcase_07 | AC | 441 ms
135,308 KB |
testcase_08 | AC | 271 ms
131,192 KB |
testcase_09 | AC | 317 ms
144,848 KB |
testcase_10 | AC | 323 ms
145,228 KB |
testcase_11 | AC | 316 ms
144,896 KB |
testcase_12 | AC | 45 ms
57,172 KB |
testcase_13 | AC | 41 ms
57,888 KB |
testcase_14 | AC | 41 ms
56,468 KB |
testcase_15 | AC | 361 ms
141,284 KB |
testcase_16 | AC | 382 ms
142,940 KB |
testcase_17 | AC | 323 ms
108,140 KB |
testcase_18 | AC | 437 ms
136,968 KB |
testcase_19 | AC | 508 ms
135,428 KB |
testcase_20 | AC | 448 ms
136,592 KB |
testcase_21 | AC | 433 ms
125,632 KB |
testcase_22 | AC | 406 ms
126,848 KB |
testcase_23 | AC | 347 ms
98,416 KB |
testcase_24 | AC | 476 ms
119,792 KB |
testcase_25 | AC | 244 ms
137,028 KB |
testcase_26 | AC | 248 ms
136,468 KB |
testcase_27 | AC | 211 ms
136,524 KB |
testcase_28 | AC | 215 ms
136,152 KB |
ソースコード
import sys,random,bisect from collections import deque,defaultdict from heapq import heapify,heappop,heappush from itertools import permutations from math import log,gcd input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) def solve(N,A,B): r = -1 M = [] del_M = [] m = [] del_m = [] res = 0 for l in range(N): if r==l-1: heappush(M,-(A[l]+B[l])) heappush(m,-(A[l]-B[l])) r = l while del_M and M[0]==del_M[0]: heappop(M) heappop(del_M) while del_m and m[0]==del_m[0]: heappop(m) heappop(del_m) while r!=N-1: if -M[0] < A[r+1]+B[r+1] and -m[0] < A[r+1]-B[r+1]: heappush(M,-(A[r+1]+B[r+1])) heappush(m,-(A[r+1]-B[r+1])) r += 1 else: break #print(l,r,M,m) res += r-l heappush(del_M,-(A[l]+B[l])) heappush(del_m,-(A[l]-B[l])) return res def brute(N,A,B): res = 0 for l in range(N): for r in range(l+1,N): if all(A[i]+B[i] < A[i+1]+B[i+1] for i in range(l,r)) and all(A[i]-B[i] < A[i+1]-B[i+1] for i in range(l,r)): res += 1 return res while False: N = 3 A = [random.randint(1,20) for i in range(N)] B = [random.randint(1,20) for i in range(N)] A.sort() print(A) print(B) print(solve(N,A,B),brute(N,A,B)) assert solve(N,A,B)==brute(N,A,B) N = int(input()) A = li() B = li() print(solve(N,A,B))