답안 #200639

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
200639 2020-02-07T18:46:46 Z stefdasca Necklace (Subtask 1-3) (BOI19_necklace1) C++14
85 / 85
451 ms 106360 KB
#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007
#define dancila 3.14159265359
#define eps 1e-9

// #define fisier 1

using namespace std;

typedef long long ll;

string a, b;
int maxLen, startA, startB;

bool rev;
int lss[3002][3002];
int lsp[3002][3002], lps[3002][3002];
void solve()
{
    memset(lss, 0, sizeof(lss));
    for(int j = 0; j < b.size(); ++j)
        for(int i = 0; i < a.size() && j + i < b.size(); ++i)
            if(a[i] == b[j + i])
                lss[i][j + i] = (i > 0 ? lss[i - 1][j + i - 1] : 0) + 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])
                lss[i + j][i] = (i > 0 ? lss[i + j - 1][i - 1] : 0) + 1;
            else
                lss[i + j][i] = 0;
    memset(lsp, 0, sizeof(lsp));
    memset(lps, 0, sizeof(lps));
    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()
{

    #ifdef fisier
        ifstream f("input.in");
        ofstream g("output.out");
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> a;
    cin >> b;
    solve();
    reverse(b.begin(), b.end());
    rev = 1;
    solve();
    cout << maxLen << '\n';
    cout << startA << " " << startB << '\n';
    return 0;
}

Compilation message

necklace.cpp: In function 'void solve()':
necklace.cpp:27:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j = 0; j < b.size(); ++j)
                    ~~^~~~~~~~~~
necklace.cpp:28:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0; i < a.size() && j + i < b.size(); ++i)
                        ~~^~~~~~~~~~
necklace.cpp:28:46: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0; i < a.size() && j + i < b.size(); ++i)
                                        ~~~~~~^~~~~~~~~~
necklace.cpp:33:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j = 0; j < a.size(); ++j)
                    ~~^~~~~~~~~~
necklace.cpp:34:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0; i < b.size() && j + i < a.size(); ++i)
                        ~~^~~~~~~~~~
necklace.cpp:34:46: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0; i < b.size() && j + i < a.size(); ++i)
                                        ~~~~~~^~~~~~~~~~
necklace.cpp:41:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < a.size(); ++i)
                    ~~^~~~~~~~~~
necklace.cpp:43:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 0; j < b.size(); ++j)
                        ~~^~~~~~~~~~
necklace.cpp:54:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < a.size(); ++i)
                    ~~^~~~~~~~~~
necklace.cpp:55:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 1; j < b.size(); ++j)
                        ~~^~~~~~~~~~
necklace.cpp:57:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < a.size(); ++i)
                    ~~^~~~~~~~~~
necklace.cpp:58:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 0; j < b.size(); ++j)
                        ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 106232 KB Output is correct
2 Correct 71 ms 106108 KB Output is correct
3 Correct 72 ms 106104 KB Output is correct
4 Correct 71 ms 106104 KB Output is correct
5 Correct 73 ms 106232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 106232 KB Output is correct
2 Correct 71 ms 106108 KB Output is correct
3 Correct 72 ms 106104 KB Output is correct
4 Correct 71 ms 106104 KB Output is correct
5 Correct 73 ms 106232 KB Output is correct
6 Correct 77 ms 106104 KB Output is correct
7 Correct 77 ms 106104 KB Output is correct
8 Correct 76 ms 106104 KB Output is correct
9 Correct 76 ms 106152 KB Output is correct
10 Correct 81 ms 106240 KB Output is correct
11 Correct 73 ms 106104 KB Output is correct
12 Correct 76 ms 106104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 106232 KB Output is correct
2 Correct 71 ms 106108 KB Output is correct
3 Correct 72 ms 106104 KB Output is correct
4 Correct 71 ms 106104 KB Output is correct
5 Correct 73 ms 106232 KB Output is correct
6 Correct 77 ms 106104 KB Output is correct
7 Correct 77 ms 106104 KB Output is correct
8 Correct 76 ms 106104 KB Output is correct
9 Correct 76 ms 106152 KB Output is correct
10 Correct 81 ms 106240 KB Output is correct
11 Correct 73 ms 106104 KB Output is correct
12 Correct 76 ms 106104 KB Output is correct
13 Correct 436 ms 106232 KB Output is correct
14 Correct 384 ms 106240 KB Output is correct
15 Correct 441 ms 106104 KB Output is correct
16 Correct 389 ms 106360 KB Output is correct
17 Correct 338 ms 106104 KB Output is correct
18 Correct 357 ms 106104 KB Output is correct
19 Correct 378 ms 106104 KB Output is correct
20 Correct 417 ms 106360 KB Output is correct
21 Correct 451 ms 106320 KB Output is correct