結果

問題 No.1703 Much Matching
ユーザー harurunharurun
提出日時 2021-09-03 14:35:53
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 3,233 bytes
コンパイル時間 197 ms
コンパイル使用メモリ 11,452 KB
実行使用メモリ 323,904 KB
最終ジャッジ日時 2023-09-30 09:25:23
合計ジャッジ時間 17,526 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,588 KB
testcase_01 AC 18 ms
8,596 KB
testcase_02 AC 18 ms
8,628 KB
testcase_03 AC 111 ms
12,792 KB
testcase_04 AC 80 ms
11,544 KB
testcase_05 AC 210 ms
17,192 KB
testcase_06 AC 672 ms
88,700 KB
testcase_07 AC 52 ms
12,812 KB
testcase_08 AC 843 ms
102,200 KB
testcase_09 AC 854 ms
120,720 KB
testcase_10 AC 145 ms
22,688 KB
testcase_11 AC 278 ms
32,908 KB
testcase_12 AC 62 ms
12,744 KB
testcase_13 AC 357 ms
47,236 KB
testcase_14 AC 30 ms
9,592 KB
testcase_15 AC 333 ms
33,816 KB
testcase_16 AC 425 ms
62,996 KB
testcase_17 AC 499 ms
68,684 KB
testcase_18 AC 24 ms
9,448 KB
testcase_19 AC 1,031 ms
142,952 KB
testcase_20 AC 125 ms
23,052 KB
testcase_21 AC 1,224 ms
166,728 KB
testcase_22 AC 640 ms
76,904 KB
testcase_23 AC 415 ms
53,148 KB
testcase_24 AC 30 ms
9,600 KB
testcase_25 AC 105 ms
15,584 KB
testcase_26 AC 432 ms
46,420 KB
testcase_27 AC 542 ms
72,512 KB
testcase_28 AC 1,153 ms
148,280 KB
testcase_29 AC 307 ms
35,564 KB
testcase_30 AC 381 ms
46,896 KB
testcase_31 AC 93 ms
13,928 KB
testcase_32 AC 646 ms
81,356 KB
testcase_33 AC 545 ms
60,304 KB
testcase_34 AC 53 ms
12,196 KB
testcase_35 AC 138 ms
21,572 KB
testcase_36 TLE -
testcase_37 AC 389 ms
24,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stderr
perr=lambda x:stderr.write(str(x)+"\n")
class INPUT:
  def __init__(self):
    self._l=open(0).read().split()
    self._length=len(self._l)
    self._index=0
    return

  def stream(self,k=1,f=int,f2=False):
    assert(-1<k)
    if self._length==self._index or self._length-self._index<k:
      raise Exception("There is no input!")
    elif f!=str:
      if k==0:
        ret=list(map(f,self._l[self._index:]))
        self._index=self._length
        return ret
      if k==1 and not f2:
        ret=f(self._l[self._index])
        self._index+=1
        return ret
      if k==1 and f2:
        ret=[f(self._l[self._index])]
        self._index+=1
        return ret
      ret=[]
      for _ in [0]*k:
        ret.append(f(self._l[self._index]))
        self._index+=1
      return ret
    else:
      if k==0:
        ret=list(self._l[self._index:])
        self._index=self._length
        return ret
      if k==1 and not f2:
        ret=self._l[self._index]
        self._index+=1
        return ret
      if k==1 and f2:
        ret=[self._l[self._index]]
        self._index+=1
        return ret
      ret=[]
      for _ in [0]*k:
        ret.append(self._l[self._index])
        self._index+=1
      return ret
pin=INPUT().stream

#pin(number[default:1],f[default:int],f2[default:False])
#if number==0 -> return left all
#listを変数で受け取るとき、必ずlistをTrueにすること。

class dsu:
  def __init__(self,n):
    assert n>0,"n must be Natural"
    self.n=n
    self.parents=[-1]*n
    return
  
  def find(self,x):
    assert x<self.n,"warning!! this is 0 index"
    if self.parents[x]<0:
      return x
    self.parents[x]=self.find(self.parents[x])
    return self.parents[x]
  
  def merge(self,x,y):
    assert x<self.n and y<self.n,"warning!! this is 0 index"
    x=self.find(x)
    y=self.find(y)
    if x==y:
      return
    if self.parents[x]>self.parents[y]:
      x,y=y,x
    self.parents[x]+=self.parents[y]
    self.parents[y]=x
    return
    
  def size(self,x):
    assert x<self.n,"warning!! this is 0 index"
    return -self.parents[self.find(x)]
    
  def same(self,x,y):
    assert x<self.n and y<self.n,"warning!! this is 0 index"
    return self.find(x)==self.find(y)
  
  def leader(self,x):
    assert x<self.n,"warning!! this is 0 index"
    if self.parents[x]<0:
      return x
    self.parents[x]=self.leader(self.parents[x])
    return self.parents[x]
  
  def groups(self):
    ld=[self.leader(i) for i in range(self.n)]
    res=[[] for _ in range(self.n)]
    for i in range(self.n):
      res[ld[i]].append(i)
    return list(filter(lambda a:a !=[],res))
    
def lcs(N,M,check):
  dp=[[0]*(M+1)for _ in[0]*(N+1)]
  for i in range(1,N+1):
    for j in range(1,M+1):
      if check[i-1][j-1]==1:
        dp[i][j]=dp[i-1][j-1]+1
      else:
        dp[i][j]=max(dp[i-1][j],dp[i][j-1])
  return dp[N][M]
  
def main():
  N,M,Q=pin(3)
  check=[[0]*M for _ in[0]*N]
  assert(1<=N<=1000)
  assert(1<=M<=1000)
  assert(1<=Q<=N*M)
  validation_set=set()
  for _ in[0]*Q:
    a,b=pin(2)
    assert(1<=a<=N)
    assert(1<=b<=M)
    validation_set.add((a,b))
    check[a-1][b-1]=1
  assert(len(validation_set)==Q)
  print(lcs(N,M,check))
  return

main()
0