QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#201605 | #7332. Dissertation | kjhhjki | AC ✓ | 201ms | 114000kb | C++14 | 1.2kb | 2023-10-05 15:27:27 | 2023-10-05 15:27:28 |
Judging History
answer
#include <bits/stdc++.h>
#define MAXN 100005
#define MAXS 1000006
#define MAXT 1003
#define For(I,A,B) for(int I = (A), endi = (B); I <= endi; ++I)
#define foR(I,A,B) for(int I = (A), endi = (B); I >= endi; --I)
#define ForE(I,A) for(int I = head[A]; I; I = e[I].nxt)
using namespace std;
typedef long long _ll;
typedef unsigned int ui;
const int INF = 0x7fffffff;
int T,n,m,ans,pos,dp[MAXT][MAXT],nxt[MAXS][27];
char ss[MAXS],tt[MAXT], *s = ss-1, *t = tt-1;
void solve()
{
cin >> ss >> tt; ans = 0;
n = strlen(ss); m = strlen(tt);
For(i,0,n) fill(nxt[i],nxt[i]+26,0);
For(i,1,m) fill(dp[i],dp[i]+m+1,INF);
foR(i,n,1)
{
For(j,0,25) nxt[i-1][j] = nxt[i][j];
nxt[i-1][s[i]-'a'] = i;
}
For(i,0,m-1) For(j,0,m-1)
{
if(dp[i][j] == INF) continue;
dp[i][j+1] = min(dp[i][j], dp[i][j+1]);
if(nxt[dp[i][j]][t[j+1]-'a'])
dp[i+1][j+1] = min(dp[i+1][j+1],nxt[dp[i][j]][t[j+1]-'a']), ans = max(ans,i+1);
}
cout << ans << '\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
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: 5700kb
input:
1 abcdefghijklmnopqrstuvwxyz bbddee
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 201ms
memory: 114000kb
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