답안 #207210

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
207210 2020-03-06T17:53:48 Z brcode Necklace (Subtask 1-3) (BOI19_necklace1) C++14
0 / 85
196 ms 216056 KB
#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

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++){
                     ~^~~~~~~~~
necklace.cpp:14:23: warning: iteration 3010 invokes undefined behavior [-Waggressive-loop-optimizations]
             lss[i][j] = 0;
             ~~~~~~~~~~^~~
necklace.cpp:13:22: note: within this loop
         for(int j=0;j<=3010;j++){
                     ~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 196 ms 216056 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 196 ms 216056 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 196 ms 216056 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -