結果

問題 No.1703 Much Matching
ユーザー harurunharurun
提出日時 2021-09-03 14:29:05
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 514 ms / 2,000 ms
コード長 731 bytes
コンパイル時間 1,081 ms
コンパイル使用メモリ 130,844 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-07-23 03:27:59
合計ジャッジ時間 5,073 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/dsu>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
using namespace atcoder;

int lcs(int N,int M,vector<vector<int>>& check){
  vector<vector<int>> dp(N+1,vector<int>(M+1,0));
  for(int i=1;i<N+1;i++){
    for(int j=1;j<M+1;j++){
      if(check.at(i-1).at(j-1)==1){
        dp.at(i).at(j)=dp.at(i-1).at(j-1)+1;
      }else{
        dp.at(i).at(j)=max(dp.at(i-1).at(j),dp.at(i).at(j-1));
      }
    }
  }
  return dp.at(N).at(M);
}

int main(){
  int N,M,Q,a,b;
  cin>>N>>M>>Q;
  dsu uf(N+M);
  vector<vector<int>>check(N,vector<int>(M,0));
  for(int i=0;i<Q;i++){
    cin>>a>>b;
    check.at(a-1).at(b-1)=1;
  }
  printf("%d\n",lcs(N,M,check));
  return 0;
}
0