Submission #356833

#TimeUsernameProblemLanguageResultExecution timeMemory
356833nicolaalexandraRound words (IZhO13_rowords)C++14
4 / 100
48 ms16952 KiB
#include <bits/stdc++.h> #define DIM 1010 using namespace std; char a[DIM],b[DIM],a2[DIM],b2[DIM]; int dp_left[DIM][DIM],dp_right[DIM][DIM]; int n,m,i,j,sol; void solve (char a[], char b[]){ memset (dp_left,0,sizeof dp_left); memset (dp_right,0,sizeof dp_right); dp_left[0][0] = 1; for (i=1;i<=n;i++) for (j=1;j<=m;j++){ dp_left[i][j] = max (dp_left[i-1][j],dp_left[i][j-1]); if (a[i] == b[j]) dp_left[i][j] = max (dp_left[i][j],dp_left[i-1][j-1] + 1); } dp_right[n+1][m+1] = 1; for (i=n;i;i--) for (j=m;j;j--){ dp_right[i][j] = max (dp_right[i+1][j],dp_right[i][j+1]); if (a[i] == b[j]) dp_right[i][j] = max (dp_right[i][j],dp_right[i+1][j+1] + 1); } for (i=1;i<=n+1;i++) for (j=1;j<=m+1;j++) sol = max (sol,dp_right[i][j] + dp_left[i-1][j-1]); } int main (){ //ifstream cin ("date.in"); //ofstream cout ("date.out"); cin>>a+1>>b+1; n = strlen (a+1), m = strlen (b+1); for (i=1;i<=n;i++) a2[n-i+1] = a[i]; for (i=1;i<=m;i++) b2[m-i+1] = b[i]; solve (a,b); solve (a,b2); solve (a2,b); solve (a2,b2); cout<<sol; return 0; }

Compilation message (stderr)

rowords.cpp: In function 'int main()':
rowords.cpp:41:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   41 |     cin>>a+1>>b+1;
      |          ~^~
rowords.cpp:41:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   41 |     cin>>a+1>>b+1;
      |               ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...