QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#606423#7332. DissertationOmar2718TL 1ms3680kbC++202.0kb2024-10-03 06:07:192024-10-03 06:07:19

Judging History

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

  • [2024-10-03 06:07:19]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3680kb
  • [2024-10-03 06:07:19]
  • 提交

answer

#include <fstream>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <climits>
#include <bits/stdc++.h>
#include <string>
#include <string.h>
#include <math.h>

#define msb(x) (31 - __builtin_clz(x))
#define int long long int
using namespace std;

void fileIO(void) {

#ifndef ONLINE_JUDGE

    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);

#endif

}
int dx[8] = {0,0,1,-1,1,-1,1,-1};
int dy[8] = {1,-1,0,0,1,-1,-1,1};
char pth[4] = {'L','R','U','D'};
int add(int a,int b,int mod){
    return ((a % mod) + (b % mod) ) % mod;
}
int sub(int a,int b,int mod){
    return ((a % mod) - (b % mod) + mod) % mod;
}
int multiply(int a,int b,int mod){
    return ((a % mod) * (b % mod)) % mod;
}
bool equal(double a,double b){
    return abs(a-b) <= 1e-7;
}
bool get_bit(int n , int i){
    return n & (1ll << i);
}
void fastIO() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}

int gcd(int x,int y){
    if(!min(x,y))
        return max(x,y);
    return gcd(max(x,y) % min(x,y), min(x,y));
}
int lcm(int x,int y){
    return (x/gcd(x,y)) * y ;
}
int fact(int u){
    if(u == 1)
        return 1;
    return u * fact(u-1);
}
int can(int x,int y){
    return x >= 0 && x < 3 && y >= 0 && y <3;
}
string a,b;
//abcd
//bcda

map<pair<int,int>,int>dp;
map<pair<int,int>,bool>vis;
int f(int i,int curr){
    int ch1=0,ch2=0,ch3=0;
    if(i == a.size() || curr == b.size())
        return 0;
    if(vis[{i,curr}])
        return dp[{i,curr}];
    vis[{i,curr}] = true;
    ch1 = f(i+1,curr);
    ch2 = f(i,curr+1);
    if(a[i] == b[curr])
        ch3 = 1 + f(i+1,curr+1);
    return dp[{i,curr}] = max({ch1,ch2,ch3});
}
void solve() {
    cin >> a >> b;
    dp.clear();vis.clear();
    cout << f(0,0) << '\n';

}

signed main() {
    fastIO();
    fileIO();
    int t;cin>>t;
    while (t--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: