QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#242733 | #7332. Dissertation | PetroTarnavskyi# | WA | 162ms | 114420kb | C++20 | 1.2kb | 2023-11-07 16:42:19 | 2023-11-07 16:42:20 |
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 ? j : 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: 5484kb
input:
1 abcdefghijklmnopqrstuvwxyz bbddee
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: -100
Wrong Answer
time: 162ms
memory: 114420kb
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:
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 4 5 5 5 5 3 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 1 5 5 5 5 5 5 5 5 5 3 5 5 5 5 5 5 5 5 5 3 5 5 5 5 5 5 5 5 5 5 5 5 5 5 3 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 ...
result:
wrong answer 1st numbers differ - expected: '4', found: '5'