QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#608841#7332. DissertationHALZOOMWA 454ms223220kbC++141.6kb2024-10-04 06:04:512024-10-04 06:04:52

Judging History

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

  • [2024-10-04 06:04:52]
  • 评测
  • 测评结果:WA
  • 用时:454ms
  • 内存:223220kb
  • [2024-10-04 06:04:51]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long int


void UwU(void){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}


void fileIO(void) {

#ifndef ONLINE_JUDGE
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
#endif
}

int dx_all[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy_all[8] = {0, 1, 0, -1, -1, 1, -1, 1};
char di[]  = {'R' , 'L' , 'U' , 'D'};
int  dx[]  = { 1  , -1  ,  0  ,  0};
int  dy[]  = { 0  , 0   ,  -1 ,  1};

const double pi = 3.14159265358979323846;
const int N = 1e3 + 5 , M = 7;
const int MOD = 1000000007;
const int inf = 1e18;

int n , m;
string s , t;
vector<array<int , 26>>nxt;
int mem[N][N];
int vis[N][N] , id = 0;
int dp(int idx , int sz){

    if(!sz) return -1;
    if(idx < 0)return n;

    int &res = mem[idx][sz];
    if(vis[idx][sz] == id)return res;

    vis[idx][sz] = id;

    int leave= dp(idx - 1 , sz);
    int take = dp(idx - 1 , sz - 1);

    take = nxt[take + 1][t[idx] - 'a'];
    return res = min(take , leave);
}


void solve() {

    ++id;
    //memset(mem , -1 , sizeof mem);

    cin >> s >> t;
    n = s.size();
    m = t.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][s[i] - 'a'] = i;
    }

    for(int i = m - 1 ; i >= 0 ; --i){
        if(dp(m - 1 , i) < n){
            cout << i << '\n';
            return;
        }
    }

}

signed main()
{

    UwU();
    fileIO();
    int test = 1;
    cin >> test;


    while(test--) {
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1
abcdefghijklmnopqrstuvwxyz
bbddee

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: -100
Wrong Answer
time: 454ms
memory: 223220kb

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
4
4
4
4
4
4
4
4
4
4
4
4
4
3
4
4
4
4
4
4
4
4
4
4
3
3
4
4
4
3
3
4
4
4
4
4
3
2
4
4
3
4
4
4
4
4
4
4
3
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
3
4
4
4
4
1
4
3
3
4
3
4
3
4
4
3
4
3
4
4
4
4
4
4
4
3
4
4
3
3
4
4
4
4
4
4
4
4
4
4
3
4
4
3
4
4
4
4
4
4
4
3
4
4
4
4
4
4
4
4
4
4
...

result:

wrong answer 3rd numbers differ - expected: '5', found: '4'