Submission #124923

# Submission time Handle Problem Language Result Execution time Memory
124923 2019-07-04T07:16:33 Z 박상수(#3055) Necklace (Subtask 1-3) (BOI19_necklace1) C++14
85 / 85
481 ms 107860 KB
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_set>
#include <bitset>
#include <time.h>
#include <limits.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define Fi first
#define Se second
#define pb push_back
#define szz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
typedef tuple<int, int, int> t3;

char A[3030], B[3030];
int la, lb;
int dp_l[3030][3030], dp1[3030][3030], dp2[3030][3030];

t3 Do(int opt) {
    for(int i=la;i;i--) for(int j=lb;j;j--) {
        if(A[i] == B[j]) dp_l[i][j] = dp_l[i+1][j+1] + 1;
        else dp_l[i][j] = 0;
    }
    memset(dp1, 0, sizeof dp1);
    for(int i=1;i<=la;i++) {
        for(int j=1;j<=lb;j++) {
            int lj = dp_l[i][j] + j - 1;
            dp1[i][lj] = max(dp1[i][lj], dp_l[i][j]);
        }
        for(int j=lb;j>=0;j--) dp1[i][j] = max(dp1[i][j], dp1[i][j+1] - 1);
    }
    for(int i=1;i<=la;i++) for(int j=1;j<=lb;j++) {
        if(A[i] == B[j]) dp_l[i][j] = dp_l[i-1][j-1] + 1;
        else dp_l[i][j] = 0;
    }
    memset(dp2, 0, sizeof dp2);
    for(int i=1;i<=la;i++) {
        for(int j=lb;j;j--) {
            int lj = j - dp_l[i][j] + 1;
            dp2[i][lj] = max(dp2[i][lj], dp_l[i][j]);
        }
        for(int j=1;j<=lb;j++) dp2[i][j] = max(dp2[i][j], dp2[i][j-1] - 1);
    }
    int ans = -1, fi = -1, fj = -1;
    for(int i=0;i<=la;i++) for(int j=0;j<=lb;j++) {
        int val = dp1[i+1][j] + dp2[i][j+1];
        if(ans < val) {
            ans = val;
            fi = i - dp2[i][j+1];
            fj = j - dp1[i+1][j];
        }
    }
    if(opt) {
        fj = lb - ans - fj;
    }
    return t3(ans, fi, fj);
}

int main() {
    scanf("%s%s", A+1, B+1);
    la = (int)strlen(A+1);
    lb = (int)strlen(B+1);
    t3 a1 = Do(0);
    reverse(B+1, B+1+lb);
    t3 a2 = Do(1);
    t3 ans = max(a1, a2);
    printf("%d\n%d %d\n", get<0>(ans), get<1>(ans), get<2>(ans));
    return 0;
}

Compilation message

necklace.cpp: In function 'int main()':
necklace.cpp:77:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s%s", A+1, B+1);
     ~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 90 ms 72696 KB Output is correct
2 Correct 85 ms 72664 KB Output is correct
3 Correct 74 ms 72568 KB Output is correct
4 Correct 74 ms 72568 KB Output is correct
5 Correct 75 ms 72696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 72696 KB Output is correct
2 Correct 85 ms 72664 KB Output is correct
3 Correct 74 ms 72568 KB Output is correct
4 Correct 74 ms 72568 KB Output is correct
5 Correct 75 ms 72696 KB Output is correct
6 Correct 82 ms 74488 KB Output is correct
7 Correct 90 ms 74460 KB Output is correct
8 Correct 81 ms 74360 KB Output is correct
9 Correct 82 ms 74360 KB Output is correct
10 Correct 83 ms 74360 KB Output is correct
11 Correct 83 ms 74364 KB Output is correct
12 Correct 84 ms 74360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 72696 KB Output is correct
2 Correct 85 ms 72664 KB Output is correct
3 Correct 74 ms 72568 KB Output is correct
4 Correct 74 ms 72568 KB Output is correct
5 Correct 75 ms 72696 KB Output is correct
6 Correct 82 ms 74488 KB Output is correct
7 Correct 90 ms 74460 KB Output is correct
8 Correct 81 ms 74360 KB Output is correct
9 Correct 82 ms 74360 KB Output is correct
10 Correct 83 ms 74360 KB Output is correct
11 Correct 83 ms 74364 KB Output is correct
12 Correct 84 ms 74360 KB Output is correct
13 Correct 478 ms 107860 KB Output is correct
14 Correct 478 ms 107820 KB Output is correct
15 Correct 474 ms 106616 KB Output is correct
16 Correct 477 ms 107768 KB Output is correct
17 Correct 471 ms 107128 KB Output is correct
18 Correct 481 ms 107640 KB Output is correct
19 Correct 468 ms 107644 KB Output is correct
20 Correct 471 ms 107132 KB Output is correct
21 Correct 472 ms 107256 KB Output is correct