QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#608850 | #7332. Dissertation | HALZOOM | AC ✓ | 805ms | 254660kb | C++14 | 1.6kb | 2024-10-04 06:15:43 | 2024-10-04 06:15:44 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long int
void UwU(void){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
void fileIO(void) {
#ifndef ONLINE_JUDGE
freopen("Input.txt", "r", stdin);
freopen("Output.txt", "w", stdout);
#endif
}
int dx_all[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy_all[8] = {0, 1, 0, -1, -1, 1, -1, 1};
char di[] = {'R' , 'L' , 'U' , 'D'};
int dx[] = { 1 , -1 , 0 , 0};
int dy[] = { 0 , 0 , -1 , 1};
const double pi = 3.14159265358979323846;
const int N = 1001 , M = 7;
const int MOD = 1000000007;
const int inf = 1e18;
int n , m;
string s , t;
vector<vector<int>>nxt;
int mem[N][N];
vector<vector<bool>>vis;
int dp(int idx , int sz){
if(!sz) return -1;
if(idx < 0)return n;
int &res = mem[idx][sz];
if(vis[idx][sz])return res;
vis[idx][sz] = true;
int leave= dp(idx - 1 , sz);
int take = dp(idx - 1 , sz - 1);
take = nxt[take + 1][t[idx] - 'a'];
return res = min(take , leave);
}
void solve() {
//memset(mem , -1 , sizeof mem);
cin >> s >> t;
n = s.size();
m = t.size();
vis.assign(m + 1 , vector<bool>(m + 1 , false));
nxt.assign(n + 2 , vector<int>(26 , n));
for (int i = n - 1 ; i >= 0; --i) {
nxt[i] = nxt[i + 1];
nxt[i][s[i] - 'a'] = i;
}
for(int i = m ; i >= 0 ; --i){
if(dp(m - 1 , i) < n){
cout << i << '\n';
return;
}
}
}
signed main()
{
UwU();
fileIO();
int test = 1;
cin >> test;
while(test--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3872kb
input:
1 abcdefghijklmnopqrstuvwxyz bbddee
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 805ms
memory: 254660kb
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