結果

問題 No.2422 regisys?
ユーザー sepa38sepa38
提出日時 2023-07-15 15:06:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,727 ms / 2,000 ms
コード長 1,925 bytes
コンパイル時間 1,144 ms
コンパイル使用メモリ 81,836 KB
実行使用メモリ 160,280 KB
最終ジャッジ日時 2023-10-19 17:35:27
合計ジャッジ時間 32,517 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
52,992 KB
testcase_01 AC 44 ms
53,540 KB
testcase_02 AC 43 ms
53,660 KB
testcase_03 AC 42 ms
53,552 KB
testcase_04 AC 42 ms
53,600 KB
testcase_05 AC 49 ms
54,336 KB
testcase_06 AC 46 ms
54,688 KB
testcase_07 AC 45 ms
53,960 KB
testcase_08 AC 45 ms
54,316 KB
testcase_09 AC 42 ms
53,480 KB
testcase_10 AC 42 ms
53,436 KB
testcase_11 AC 43 ms
53,720 KB
testcase_12 AC 43 ms
53,044 KB
testcase_13 AC 47 ms
54,136 KB
testcase_14 AC 44 ms
53,316 KB
testcase_15 AC 46 ms
54,052 KB
testcase_16 AC 44 ms
53,556 KB
testcase_17 AC 44 ms
53,800 KB
testcase_18 AC 43 ms
53,376 KB
testcase_19 AC 45 ms
54,308 KB
testcase_20 AC 45 ms
54,396 KB
testcase_21 AC 46 ms
53,916 KB
testcase_22 AC 43 ms
53,608 KB
testcase_23 AC 48 ms
54,244 KB
testcase_24 AC 45 ms
53,508 KB
testcase_25 AC 43 ms
53,628 KB
testcase_26 AC 42 ms
53,076 KB
testcase_27 AC 43 ms
53,516 KB
testcase_28 AC 42 ms
53,736 KB
testcase_29 AC 41 ms
53,476 KB
testcase_30 AC 42 ms
53,636 KB
testcase_31 AC 490 ms
102,160 KB
testcase_32 AC 860 ms
109,248 KB
testcase_33 AC 452 ms
100,992 KB
testcase_34 AC 414 ms
90,308 KB
testcase_35 AC 566 ms
111,584 KB
testcase_36 AC 737 ms
103,612 KB
testcase_37 AC 963 ms
112,688 KB
testcase_38 AC 623 ms
99,232 KB
testcase_39 AC 484 ms
92,928 KB
testcase_40 AC 350 ms
90,380 KB
testcase_41 AC 554 ms
95,760 KB
testcase_42 AC 832 ms
125,368 KB
testcase_43 AC 669 ms
100,084 KB
testcase_44 AC 947 ms
132,404 KB
testcase_45 AC 776 ms
121,928 KB
testcase_46 AC 970 ms
131,560 KB
testcase_47 AC 793 ms
110,296 KB
testcase_48 AC 917 ms
141,080 KB
testcase_49 AC 976 ms
123,624 KB
testcase_50 AC 858 ms
137,332 KB
testcase_51 AC 1,441 ms
143,344 KB
testcase_52 AC 451 ms
103,040 KB
testcase_53 AC 942 ms
126,152 KB
testcase_54 AC 1,345 ms
158,972 KB
testcase_55 AC 1,024 ms
136,364 KB
testcase_56 AC 881 ms
125,772 KB
testcase_57 AC 1,617 ms
160,280 KB
testcase_58 AC 1,727 ms
159,916 KB
testcase_59 AC 1,657 ms
159,916 KB
testcase_60 AC 1,611 ms
159,712 KB
testcase_61 AC 41 ms
52,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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
0