結果
問題 | No.2422 regisys? |
ユーザー | sepa38 |
提出日時 | 2023-07-15 15:05:10 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,917 ms / 2,000 ms |
コード長 | 1,885 bytes |
コンパイル時間 | 256 ms |
コンパイル使用メモリ | 81,664 KB |
実行使用メモリ | 154,632 KB |
最終ジャッジ日時 | 2024-09-17 00:00:55 |
合計ジャッジ時間 | 34,945 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 61 |
ソースコード
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() b2.sort() 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