結果

問題 No.1703 Much Matching
ユーザー vwxyzvwxyz
提出日時 2021-10-08 23:35:09
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 1,948 ms / 2,000 ms
コード長 603 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 49,792 KB
最終ジャッジ日時 2024-07-23 07:49:45
合計ジャッジ時間 14,413 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
import sys
readline=sys.stdin.readline

def LIS(lst,weakly=False,max_value=float('inf')):
    f=bisect.bisect_right if weakly else bisect.bisect_left
    dp=[max_value]*(min(N,M)+1)
    for x in lst:
        i=f(dp,x)
        dp[i]=x
    n=bisect.bisect_left(dp,max_value)
    return n

N,M,Q=map(int,readline().split())
AB=[[0]*M for i in range(N)]
for _ in range(Q):
    a,b=map(int,readline().split())
    a-=1
    b-=1
    AB[a][b]=1
lst=[]
for a in range(N):
    for b in range(M-1,-1,-1):
        if AB[a][b]:
            lst.append(b)
inf=1<<30
ans=LIS(lst,max_value=inf)
print(ans)
0