Submission #357660

#TimeUsernameProblemLanguageResultExecution timeMemory
357660nicolaalexandraRound words (IZhO13_rowords)C++14
24 / 100
100 ms32876 KiB
#include <bits/stdc++.h> #define DIM 2010 using namespace std; char a[DIM],b[DIM],a2[DIM],b2[DIM]; int dp[DIM][DIM]; int n,m,i,j,sol; void solve (char a[], char b[]){ memset (dp,0,sizeof dp); for (i=1;i<=n;i++) for (j=1;j<=m;j++){ dp[i][j] = max (dp[i-1][j],dp[i][j-1]); if (a[i] == b[j]) dp[i][j] = max (dp[i][j],dp[i-1][j-1] + 1); } for (int poz=1;poz<=n;poz++){ int i = poz, j = m, cnt = 0; while (i > max(0,poz - n/2) && j >= 1){ if (a[i] == b[j]){ cnt++; i--, j--; } else { if (dp[i][j-1] >= dp[i-1][j]) j--; else i--; } } sol = max (sol,cnt); } } 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]; for (i=1;i<=n;i++) a[i+n] = a[i]; n *= 2; solve (a,b); solve (a,b2); for (i=1;i<=n/2;i++) a2[i+n/2] = a2[i]; solve (a2,b); cout<<sol; return 0; }

Compilation message (stderr)

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