結果

問題 No.2422 regisys?
ユーザー sepa38sepa38
提出日時 2023-07-15 15:05:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,947 ms / 2,000 ms
コード長 1,885 bytes
コンパイル時間 233 ms
コンパイル使用メモリ 81,792 KB
実行使用メモリ 153,896 KB
最終ジャッジ日時 2023-10-17 00:27:45
合計ジャッジ時間 39,428 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
53,616 KB
testcase_01 AC 35 ms
53,616 KB
testcase_02 AC 35 ms
55,664 KB
testcase_03 AC 34 ms
53,616 KB
testcase_04 AC 35 ms
53,616 KB
testcase_05 AC 36 ms
55,664 KB
testcase_06 AC 39 ms
55,664 KB
testcase_07 AC 36 ms
55,664 KB
testcase_08 AC 40 ms
55,664 KB
testcase_09 AC 35 ms
53,616 KB
testcase_10 AC 37 ms
53,616 KB
testcase_11 AC 36 ms
55,664 KB
testcase_12 AC 33 ms
53,616 KB
testcase_13 AC 37 ms
55,664 KB
testcase_14 AC 34 ms
53,616 KB
testcase_15 AC 35 ms
55,664 KB
testcase_16 AC 34 ms
53,616 KB
testcase_17 AC 35 ms
55,664 KB
testcase_18 AC 35 ms
53,616 KB
testcase_19 AC 36 ms
55,664 KB
testcase_20 AC 36 ms
55,664 KB
testcase_21 AC 39 ms
55,664 KB
testcase_22 AC 37 ms
53,616 KB
testcase_23 AC 37 ms
55,664 KB
testcase_24 AC 38 ms
53,616 KB
testcase_25 AC 33 ms
53,616 KB
testcase_26 AC 34 ms
53,616 KB
testcase_27 AC 34 ms
53,616 KB
testcase_28 AC 35 ms
55,664 KB
testcase_29 AC 38 ms
53,616 KB
testcase_30 AC 34 ms
53,616 KB
testcase_31 AC 588 ms
102,696 KB
testcase_32 AC 864 ms
108,700 KB
testcase_33 AC 553 ms
101,924 KB
testcase_34 AC 372 ms
91,916 KB
testcase_35 AC 678 ms
109,304 KB
testcase_36 AC 709 ms
100,892 KB
testcase_37 AC 991 ms
110,208 KB
testcase_38 AC 558 ms
99,352 KB
testcase_39 AC 451 ms
93,048 KB
testcase_40 AC 398 ms
89,756 KB
testcase_41 AC 520 ms
95,800 KB
testcase_42 AC 1,116 ms
126,680 KB
testcase_43 AC 687 ms
100,640 KB
testcase_44 AC 1,240 ms
129,984 KB
testcase_45 AC 1,043 ms
121,992 KB
testcase_46 AC 1,278 ms
131,128 KB
testcase_47 AC 879 ms
111,284 KB
testcase_48 AC 1,291 ms
139,272 KB
testcase_49 AC 1,085 ms
120,632 KB
testcase_50 AC 1,212 ms
134,776 KB
testcase_51 AC 1,626 ms
144,724 KB
testcase_52 AC 570 ms
103,160 KB
testcase_53 AC 1,263 ms
126,832 KB
testcase_54 AC 1,647 ms
149,688 KB
testcase_55 AC 1,321 ms
130,488 KB
testcase_56 AC 1,001 ms
128,340 KB
testcase_57 AC 1,902 ms
153,792 KB
testcase_58 AC 1,947 ms
153,896 KB
testcase_59 AC 1,900 ms
153,616 KB
testcase_60 AC 1,918 ms
153,724 KB
testcase_61 AC 35 ms
53,620 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()
  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
0