結果
問題 | No.2422 regisys? |
ユーザー | sepa38 |
提出日時 | 2023-07-15 15:06:37 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,387 ms / 2,000 ms |
コード長 | 1,925 bytes |
コンパイル時間 | 606 ms |
コンパイル使用メモリ | 82,472 KB |
実行使用メモリ | 160,460 KB |
最終ジャッジ日時 | 2024-09-19 13:55:02 |
合計ジャッジ時間 | 26,321 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
52,992 KB |
testcase_01 | AC | 38 ms
53,120 KB |
testcase_02 | AC | 40 ms
53,760 KB |
testcase_03 | AC | 38 ms
53,632 KB |
testcase_04 | AC | 39 ms
53,632 KB |
testcase_05 | AC | 40 ms
54,272 KB |
testcase_06 | AC | 41 ms
54,528 KB |
testcase_07 | AC | 37 ms
53,760 KB |
testcase_08 | AC | 38 ms
54,144 KB |
testcase_09 | AC | 37 ms
53,248 KB |
testcase_10 | AC | 35 ms
53,500 KB |
testcase_11 | AC | 36 ms
54,016 KB |
testcase_12 | AC | 36 ms
52,608 KB |
testcase_13 | AC | 39 ms
54,272 KB |
testcase_14 | AC | 42 ms
53,120 KB |
testcase_15 | AC | 41 ms
54,016 KB |
testcase_16 | AC | 37 ms
53,120 KB |
testcase_17 | AC | 37 ms
53,632 KB |
testcase_18 | AC | 36 ms
53,120 KB |
testcase_19 | AC | 40 ms
54,400 KB |
testcase_20 | AC | 39 ms
54,528 KB |
testcase_21 | AC | 38 ms
54,144 KB |
testcase_22 | AC | 38 ms
53,632 KB |
testcase_23 | AC | 40 ms
54,144 KB |
testcase_24 | AC | 37 ms
53,760 KB |
testcase_25 | AC | 38 ms
53,248 KB |
testcase_26 | AC | 36 ms
52,992 KB |
testcase_27 | AC | 38 ms
53,248 KB |
testcase_28 | AC | 40 ms
53,632 KB |
testcase_29 | AC | 36 ms
53,120 KB |
testcase_30 | AC | 37 ms
53,888 KB |
testcase_31 | AC | 427 ms
102,524 KB |
testcase_32 | AC | 720 ms
109,304 KB |
testcase_33 | AC | 392 ms
101,148 KB |
testcase_34 | AC | 363 ms
90,084 KB |
testcase_35 | AC | 488 ms
111,816 KB |
testcase_36 | AC | 613 ms
104,952 KB |
testcase_37 | AC | 798 ms
112,844 KB |
testcase_38 | AC | 514 ms
99,172 KB |
testcase_39 | AC | 404 ms
93,108 KB |
testcase_40 | AC | 308 ms
90,464 KB |
testcase_41 | AC | 465 ms
95,804 KB |
testcase_42 | AC | 705 ms
126,552 KB |
testcase_43 | AC | 558 ms
100,204 KB |
testcase_44 | AC | 779 ms
132,640 KB |
testcase_45 | AC | 649 ms
121,892 KB |
testcase_46 | AC | 806 ms
131,872 KB |
testcase_47 | AC | 661 ms
110,724 KB |
testcase_48 | AC | 763 ms
141,868 KB |
testcase_49 | AC | 818 ms
123,956 KB |
testcase_50 | AC | 706 ms
137,536 KB |
testcase_51 | AC | 1,168 ms
143,868 KB |
testcase_52 | AC | 384 ms
102,584 KB |
testcase_53 | AC | 777 ms
126,580 KB |
testcase_54 | AC | 1,066 ms
159,404 KB |
testcase_55 | AC | 848 ms
136,360 KB |
testcase_56 | AC | 725 ms
125,732 KB |
testcase_57 | AC | 1,334 ms
160,460 KB |
testcase_58 | AC | 1,387 ms
159,864 KB |
testcase_59 | AC | 1,353 ms
160,004 KB |
testcase_60 | AC | 1,337 ms
160,072 KB |
testcase_61 | AC | 35 ms
53,120 KB |
ソースコード
import heapq n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) ls = [list(map(int, input().split())) for _ in range(m)] def solve(n, m, a, b, ls): a2 = [[a[i], i] for i in range(n)] b2 = [[b[i], i] for i in range(n)] a2.sort(key = lambda x: x[0]) b2.sort(key = lambda x: x[0]) ls.sort(key = lambda x: x[1]) flg = [0] * n h1 = [] h2 = [] idxa = 0 idxb = 0 for t, c in ls: while idxa < n: if a2[idxa][0] > c: break idx = a2[idxa][1] heapq.heappush(h1, (-b[idx])*n+idx) idxa += 1 while idxb < n: if b2[idxb][0] > c: break idx = b2[idxb][1] heapq.heappush(h2, (-a[idx])*n+idx) idxb += 1 if t: while h2: tmp = heapq.heappop(h2) x, i = divmod(tmp, n) if flg[i] == 0: flg[i] = 1 break else: while h1: tmp = heapq.heappop(h1) x, i = divmod(tmp, n) if flg[i] == 0: flg[i] = 1 break # print(flg, t, c) # print(h1, h2) return n - sum(flg) # print(flg) from itertools import permutations def naive(n, m, a, b, ls): ans = n for p in permutations(range(m)): res = n for i in range(m): t, c = ls[i] if t: res -= b[p[i]] <= c else: res -= a[p[i]] <= c ans = min(ans, res) return ans print(solve(n, m, a, b, ls)) # print(naive(n, m, a, b, ls)) exit() import random for _ in range(100): n, m = random.randint(1, 5), random.randint(1, 5) # m = max(m, n) a = [random.randint(1, 10**9) for _ in range(n)] b = [random.randint(1, 10**9) for _ in range(n)] ls = [[random.randint(0, 1), random.randint(1, 10**9)] for _ in range(m)] solve(n, m, a, b, ls) continue if solve(n, m, a, b, ls) != naive(n, m, a, b, ls): print(n, m) print(*a) print(*b) for t, c in ls: print(t, c) break