QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#608846#7332. DissertationHALZOOMTL 1ms3696kbC++141.6kb2024-10-04 06:10:272024-10-04 06:10:27

Judging History

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

  • [2024-10-04 06:10:27]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3696kb
  • [2024-10-04 06:10:27]
  • 提交

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 = 1001 , M = 7;
const int MOD = 1000000007;
const int inf = 1e18;

int n , m;
string s , t;
vector<vector<int>>nxt;
int mem[N][N];
vector<vector<bool>>vis;
int dp(int idx , int sz){

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

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

    vis[idx][sz] = true;

    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() {

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

    cin >> s >> t;
    n = s.size();
    m = t.size();

    vis.assign(N , vector<bool>(N , false));
    nxt.assign(n + 2 , vector<int>(26 , n));

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

    for(int i = m  ; 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: 3696kb

input:

1
abcdefghijklmnopqrstuvwxyz
bbddee

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: -100
Time Limit Exceeded

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:


result: