Submission #140269

#TimeUsernameProblemLanguageResultExecution timeMemory
140269ae04071Necklace (Subtask 1-3) (BOI19_necklace1)C++11
85 / 85
391 ms508 KiB
#include <bits/stdc++.h> using namespace std; int n,m; char s[3010],t[3010]; int pi[3010],fm[3010],bm[3010]; void getpi() { int i=0; for(int j=1;j<m;j++) { while(i && t[i]!=t[j]) i = pi[i-1]; if(t[i]==t[j]) pi[j]=++i; } } void kmp(int *arr) { int j=0; for(int i=0;i<n;i++) { while(j && s[i]!=t[j]) { j = pi[j-1]; } if(s[i]==t[j]) { ++j; if(j==m) { j=pi[j-1]; } } arr[i] = j; } } int ans=0,ai,aj,f; void solve() { for(int i=0;i<m;i++) { getpi(); kmp(fm); reverse(s, s+n); reverse(t, t+m); getpi(); kmp(bm); reverse(s, s+n); reverse(t,t+m); reverse(bm, bm+n); for(int j=0;j<n-1;j++) { int v = min(fm[j],m-i) + min(bm[j+1],i); if(ans < v) { ans = v; ai = j - fm[j] + 1; if(!f) aj = i - min(bm[j+1], i); else aj = m-i - min(fm[j], m-i); } } char ch = t[0]; for(int j=0;j<m-1;j++) t[j]=t[j+1]; t[m-1]=ch; } } int main() { scanf("%s%s",s,t); n=strlen(s); m=strlen(t); solve(); f=1; reverse(t,t+m); solve(); printf("%d\n%d %d\n",ans,ai,aj); return 0; }

Compilation message (stderr)

necklace.cpp: In function 'int main()':
necklace.cpp:63:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s%s",s,t);
     ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...