QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#608138#7332. Dissertation_SherbinyAC ✓360ms113748kbC++201.2kb2024-10-03 19:02:022024-10-03 19:02:02

Judging History

你现在查看的是最新测评结果

  • [2024-10-03 19:02:02]
  • 评测
  • 测评结果:AC
  • 用时:360ms
  • 内存:113748kb
  • [2024-10-03 19:02:02]
  • 提交

answer

// Author: _Sherbiny

#include "bits/stdc++.h"

#ifdef DBG

#include "./debug.h"

#else
#define dbg(...)
#endif
using namespace std;
typedef long long ll;
#define endl '\n'
///////////////////////////////////
const int oo = 2e9, N = 1001;
vector<array<int, 26>> nxt;
string a, b;
int n, m;
int dp[N][N], vis[N][N], id = 0;

int go(int i, int rem) {
    if (!rem) return -1;
    if (i < 0) return n;

    int &res = dp[i][rem];
    if (vis[i][rem] == id) return res;
    vis[i][rem] = id;

    res = go(i - 1, rem);
    int ind = go(i - 1, rem - 1);

    ind = nxt[ind + 1][b[i] - 'a'];

    return res = min(ind, res);
}

void magic() {
    ++id;
    cin >> a >> b;
    n = a.size(), m = b.size();
    nxt.assign(n + 2, {});

    nxt[n].fill(n);
    nxt[n + 1].fill(n);

    for (int i = n - 1; i >= 0; --i) {
        nxt[i] = nxt[i + 1];
        nxt[i][a[i] - 'a'] = i;
    }


    for (int sz = m; sz >= 0; --sz) {
        if (go(m - 1, sz) < n) {
            cout << sz << endl;
            return;
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--) magic();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5736kb

input:

1
abcdefghijklmnopqrstuvwxyz
bbddee

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 360ms
memory: 113748kb

input:

4106
ababbbab
babaa
aabaaaaa
bbbab
aababaab
bbaab
aababbba
aaaaa
aabbabbb
baabb
aabababb
abbbb
aabbabab
babaa
aaabbaaa
aaabb
aaababba
ababb
aabbbaba
abaaa
abbbaaba
bbbab
aaaababb
aabab
abbbaaba
abbba
abbbabbb
bbbaa
aaabaaaa
aaabb
abbababb
baaaa
aaaababb
babbb
abaaaaab
aabaa
ababaaab
aabaa
abbbabaa
b...

output:

4
2
5
4
4
5
4
5
5
4
5
5
5
4
4
3
4
4
5
4
5
5
5
4
4
5
3
3
5
4
4
3
3
5
4
5
4
5
3
2
5
4
3
4
4
5
5
5
5
5
3
4
5
4
4
4
4
5
5
4
5
4
5
5
4
4
5
4
4
4
4
4
5
5
4
5
4
5
5
5
5
5
4
5
4
5
5
5
3
4
4
5
4
1
5
3
3
4
3
5
3
4
4
3
4
3
4
5
5
5
4
5
4
3
4
4
3
3
4
5
4
5
4
5
4
4
5
4
3
5
5
3
5
5
4
5
4
5
4
3
4
4
4
4
4
4
5
5
5
5
...

result:

ok 4106 numbers