Submission #703851

# Submission time Handle Problem Language Result Execution time Memory
703851 2023-02-28T17:22:54 Z asdfasdfasdfasdf Round words (IZhO13_rowords) C++14
76 / 100
15 ms 980 KB
#include <bits/stdc++.h>

using namespace std;

int now_ih[4444];
int pre_ih[4444];
int now_iv[4444];
int pre_iv[4444];

vector<int> tree[1 << 13];

const int sz = 1 << 12;

string A,B;
int n,m;

int answer=0;

void add(int idx,int value)
{
    idx|=sz;
    tree[idx].push_back(value);
    return;
}

int query(int l,int r,int k)
{
    l|=sz;
    r|=sz;
    int ret=0;
    while(l<=r)
    {
        if(l&1)
            ret+=upper_bound(tree[l].begin(),tree[l].end(),k)-tree[l].begin(),l++;
        if(~r&1)
            ret+=upper_bound(tree[r].begin(),tree[r].end(),k)-tree[r].begin(),r--;
        l>>=1;
        r>>=1;
    }
    return ret;
}

void fill_pre()
{
    for(int i=0;i<=2*m;i++)
    {
        pre_ih[i]=now_ih[i];
        pre_iv[i]=now_iv[i];
        now_ih[i]=0;
        now_iv[i]=0;
    }
    return;
}

void init()
{

    for(int i=0;i<=2*m;i++)
        pre_ih[i]=i;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=2*m;j++)
        {
            if(A[i]==B[j])
            {
                now_ih[j]=now_iv[j-1];
                now_iv[j]=pre_ih[j];
            }
            else
            {
                now_ih[j]=max(now_iv[j-1],pre_ih[j]);
                now_iv[j]=min(now_iv[j-1],pre_ih[j]);
            }
        }
        fill_pre();
    }

    for(int i=1;i<=2*m;i++)
        add(i,pre_ih[i]);

    for(int i=sz-1;i;i--)
    {
        tree[i].resize(tree[i*2].size()+tree[i*2+1].size());
        merge(tree[i*2].begin(),tree[i*2].end(),tree[i*2+1].begin(),tree[i*2+1].end(),tree[i].begin());
    }

    return;
}

void solve()
{
    for(int i=0;i<=m;i++)
        answer=max(answer,query(i+1,i+m,i));

    return;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string a,b;
    cin >> a;
    cin >> b;
    A=" ";
    B=" ";
    B+=a;
    B+=a;
    A+=b;
    n=b.size();
    m=a.size();
    init();
    solve();
    cout << answer;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Correct 1 ms 476 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 2 ms 724 KB Output is correct
7 Correct 6 ms 724 KB Output is correct
8 Incorrect 11 ms 724 KB Output isn't correct
9 Correct 12 ms 656 KB Output is correct
10 Correct 10 ms 724 KB Output is correct
11 Correct 10 ms 704 KB Output is correct
12 Correct 5 ms 724 KB Output is correct
13 Correct 14 ms 724 KB Output is correct
14 Correct 15 ms 724 KB Output is correct
15 Correct 13 ms 724 KB Output is correct
16 Correct 15 ms 780 KB Output is correct
17 Incorrect 9 ms 852 KB Output isn't correct
18 Correct 12 ms 848 KB Output is correct
19 Correct 10 ms 648 KB Output is correct
20 Incorrect 14 ms 772 KB Output isn't correct
21 Correct 4 ms 852 KB Output is correct
22 Correct 5 ms 852 KB Output is correct
23 Correct 6 ms 904 KB Output is correct
24 Incorrect 7 ms 904 KB Output isn't correct
25 Incorrect 9 ms 980 KB Output isn't correct