結果

問題 No.1703 Much Matching
ユーザー harurunharurun
提出日時 2021-09-03 14:30:56
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 494 ms / 2,000 ms
コード長 731 bytes
コンパイル時間 854 ms
コンパイル使用メモリ 80,452 KB
最終ジャッジ日時 2025-01-24 04:27:20
ジャッジサーバーID
(参考情報)
judge4 / 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