QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#242759 | #7332. Dissertation | PetroTarnavskyi# | AC ✓ | 152ms | 114624kb | C++20 | 1.2kb | 2023-11-07 16:51:04 | 2023-11-07 16:51:05 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); i--)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
const int ALP = 26;
const int N = 1 << 20;
const int M = 1 << 10;
int nxt[N][ALP];
int dp[M][M];
void solve()
{
string s, t;
cin >> s >> t;
int n = SZ(s), m = SZ(t);
FOR(j, 0, ALP)
nxt[n][j] = n;
RFOR(i, n, 0)
FOR(j, 0, ALP)
nxt[i][j] = s[i] - 'a' == j ? i : nxt[i + 1][j];
FOR(i, 0, m + 1)
FOR(j, 0, m + 1)
dp[i][j] = n;
dp[0][0] = 0;
int ans = 0;
FOR(i, 0, m)
FOR(j, 0, m + 1)
{
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
int k = dp[i][j];
if (j < m && nxt[k][t[i] - 'a'] < n)
{
dp[i + 1][j + 1] = min(dp[i + 1][j + 1], nxt[k][t[i] - 'a'] + 1);
ans = max(ans, j + 1);
}
}
cout << ans << "\n";
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(15);
int t;
cin >> t;
while (t--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5556kb
input:
1 abcdefghijklmnopqrstuvwxyz bbddee
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 152ms
memory: 114624kb
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