Submission #207211

#TimeUsernameProblemLanguageResultExecution timeMemory
207211brcodeNecklace (Subtask 1-3) (BOI19_necklace1)C++14
85 / 85
490 ms106872 KiB
#include <iostream> #include <bits/stdc++.h> using namespace std; const int MAXN = 3010; string a,b; int lss[MAXN][MAXN]; int lsp[MAXN][MAXN]; int lps[MAXN][MAXN]; bool rev; int maxlen,startA,startB; void solve(){ for(int i=0;i<3010;i++){ for(int j=0;j<3010;j++){ lss[i][j] = 0; lps[i][j] = 0; lsp[i][j] = 0; } } for(int j=0;j<b.size();j++){ for(int i=0;i<a.size() && (i+j)<b.size();i++){ if(a[i] == b[j+i]){ if(i){ lss[i][j+i] = lss[i-1][j+i-1]+1; }else{ lss[i][j+i] = 1; } }else{ lss[i][j+i] = 0; } } } for(int j=0;j<a.size();j++){ for(int i=0;i<b.size() && j+i<a.size();i++){ if(a[i+j] == b[i]){ if(i){ lss[i+j][i] = lss[i+j-1][i-1]+1; }else{ lss[i+j][i] =1; } }else{ lss[i+j][i] = 0; } } } for(int i=0;i<a.size();i++){ for(int j=0;j<b.size();j++){ int x = lss[i][j]; if(x == 0){ continue; } if(j-x>=0){ lsp[i][j-x] = max(lsp[i][j-x],x); } if(i-x>=0){ lps[i-x][j] = max(lps[i-x][j],x); } } } for(int i=0;i<a.size();i++){ for(int j=1;j<b.size();j++){ lsp[i][j] = max(lsp[i][j],lsp[i][j-1]-1); } } for(int i=0;i<a.size();i++){ for(int j=0;j<b.size();j++){ int x = lsp[i][j]; int y = lps[i][j]; if(x+y>maxlen){ maxlen = x+y; startA = i-x+1; startB = j-y+1; if(rev){ startB = b.size()-(j+x+1); } } } } } int main(){ cin>>a; cin>>b; solve(); reverse(b.begin(),b.end()); rev = 1; solve(); cout<<maxlen<<endl; cout<<startA<<" "<<startB<<endl; }

Compilation message (stderr)

necklace.cpp: In function 'void solve()':
necklace.cpp:19:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j=0;j<b.size();j++){
                 ~^~~~~~~~~
necklace.cpp:20:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<a.size() && (i+j)<b.size();i++){
                     ~^~~~~~~~~
necklace.cpp:20:40: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<a.size() && (i+j)<b.size();i++){
                                   ~~~~~^~~~~~~~~
necklace.cpp:32:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j=0;j<a.size();j++){
                 ~^~~~~~~~~
necklace.cpp:33:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<b.size() && j+i<a.size();i++){
                     ~^~~~~~~~~
necklace.cpp:33:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<b.size() && j+i<a.size();i++){
                                   ~~~^~~~~~~~~
necklace.cpp:45:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<a.size();i++){
                 ~^~~~~~~~~
necklace.cpp:46:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0;j<b.size();j++){
                     ~^~~~~~~~~
necklace.cpp:59:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<a.size();i++){
                 ~^~~~~~~~~
necklace.cpp:60:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=1;j<b.size();j++){
                     ~^~~~~~~~~
necklace.cpp:64:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<a.size();i++){
                 ~^~~~~~~~~
necklace.cpp:65:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0;j<b.size();j++){
                     ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...