Submission #18746577


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,M;
int A[1010],B[1010];

int dp[2020][2020];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,N) cin>>A[i];
	FOR(i,M) cin>>B[i];
	
	FOR(x,N+1) FOR(y,M+1) dp[x][y]=1<<30;
	dp[0][0]=0;
	FOR(x,N+1) FOR(y,M+1) {
		if(x+1<=N) dp[x+1][y]=min(dp[x+1][y],dp[x][y]+1);
		if(y+1<=M) dp[x][y+1]=min(dp[x][y+1],dp[x][y]+1);
		if(x+1<=N&&y+1<=M) dp[x+1][y+1]=min(dp[x+1][y+1],dp[x][y]+(A[x]!=B[y]));
	}
	cout<<dp[N][M]<<endl;
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

Submission Info

Submission Time
Task E - Sequence Matching
User kmjp
Language C++ (GCC 9.2.1)
Score 500
Code Size 1293 Byte
Status AC
Exec Time 22 ms
Memory 11564 KB

Compile Error

./Main.cpp: In function ‘void solve()’:
./Main.cpp:22:8: warning: unused variable ‘j’ [-Wunused-variable]
   22 |  int i,j,k,l,r,x,y; string s;
      |        ^
./Main.cpp:22:10: warning: unused variable ‘k’ [-Wunused-variable]
   22 |  int i,j,k,l,r,x,y; string s;
      |          ^
./Main.cpp:22:12: warning: unused variable ‘l’ [-Wunused-variable]
   22 |  int i,j,k,l,r,x,y; string s;
      |            ^
./Main.cpp:22:14: warning: unused variable ‘r’ [-Wunused-variable]
   22 |  int i,j,k,l,r,x,y; string s;
      |              ^
./Main.cpp: In function ‘int main(int, char**)’:
./Main.cpp:6:28: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
    6 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                            ^
./Main.cpp:45:38: note: in expansion of macro ‘FOR’
   45 |  FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
      |                                      ^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 31
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All extreme_00.txt, extreme_01.txt, extreme_02.txt, extreme_03.txt, extreme_04.txt, extreme_05.txt, extreme_06.txt, handmade_00.txt, handmade_01.txt, pattern_00.txt, pattern_01.txt, pattern_02.txt, pattern_03.txt, pattern_04.txt, pattern_05.txt, pattern_06.txt, pattern_07.txt, pattern_08.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
extreme_00.txt AC 14 ms 11352 KB
extreme_01.txt AC 15 ms 11396 KB
extreme_02.txt AC 16 ms 11472 KB
extreme_03.txt AC 15 ms 11564 KB
extreme_04.txt AC 16 ms 11524 KB
extreme_05.txt AC 3 ms 3592 KB
extreme_06.txt AC 6 ms 7512 KB
handmade_00.txt AC 2 ms 3508 KB
handmade_01.txt AC 2 ms 3620 KB
pattern_00.txt AC 17 ms 11472 KB
pattern_01.txt AC 13 ms 11564 KB
pattern_02.txt AC 15 ms 11564 KB
pattern_03.txt AC 7 ms 6692 KB
pattern_04.txt AC 3 ms 4032 KB
pattern_05.txt AC 3 ms 5188 KB
pattern_06.txt AC 7 ms 7220 KB
pattern_07.txt AC 3 ms 4800 KB
pattern_08.txt AC 7 ms 7052 KB
random_00.txt AC 22 ms 11360 KB
random_01.txt AC 14 ms 11484 KB
random_02.txt AC 21 ms 11488 KB
random_03.txt AC 4 ms 4040 KB
random_04.txt AC 2 ms 3700 KB
random_05.txt AC 4 ms 5180 KB
random_06.txt AC 7 ms 7160 KB
random_07.txt AC 5 ms 4672 KB
random_08.txt AC 10 ms 7048 KB
random_09.txt AC 14 ms 9164 KB
sample_01.txt AC 2 ms 3632 KB
sample_02.txt AC 2 ms 3672 KB
sample_03.txt AC 3 ms 3644 KB