結果

問題 No.1703 Much Matching
ユーザー vwxyz
提出日時 2021-10-08 23:35:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 618 ms / 2,000 ms
コード長 603 bytes
コンパイル時間 262 ms
コンパイル使用メモリ 82,200 KB
実行使用メモリ 159,048 KB
最終ジャッジ日時 2024-07-23 07:50:25
合計ジャッジ時間 7,183 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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