QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#608849 | #7332. Dissertation | HALZOOM | TL | 1ms | 4024kb | C++14 | 1.1kb | 2024-10-04 06:14:29 | 2024-10-04 06:14:29 |
Judging History
answer
// Author: _Sherbiny
#include "bits/stdc++.h"
#ifdef DBG
#include "./debug.h"
#else
#define dbg(...)
#endif
using namespace std;
typedef long long ll;
#define endl '\n'
///////////////////////////////////
const int oo = 2e9, N = 1001;
vector<vector<int>> nxt;
string a, b;
int n, m;
int dp[N][N];
vector<vector<bool>>vis;
int go(int i, int sz) {
if (!sz) return -1;
if (i < 0) return n;
int &res = dp[i][sz];
if (vis[i][sz]) return res;
vis[i][sz] = true;
res = go(i - 1, sz);
int ind = go(i - 1, sz - 1);
ind = nxt[ind + 1][b[i] - 'a'];
return res = min(ind, res);
}
void magic() {
cin >> a >> b;
n = a.size(), m = b.size();
nxt.assign(n + 2, vector<int>(26 ,n));
vis.assign(N, vector<bool>(N));
for (int i = n - 1; i >= 0; --i) {
nxt[i] = nxt[i + 1];
nxt[i][a[i] - 'a'] = i;
}
for (int sz = m; sz >= 0; --sz) {
if (go(m - 1, sz) < n) {
cout << sz << endl;
return;
}
}
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--) magic();
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 4024kb
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:
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 ...