QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#196670 | #7234. Pencil of Wishing | jeffqi | WA | 0ms | 3636kb | C++20 | 2.6kb | 2023-10-01 21:19:04 | 2023-10-01 21:19:04 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define eb emplace_back
#define pb push_back
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(v) ((int)v.size())
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define umap unordered_map
#define uset unordered_set
#define mset multiset
#define ui unsigned int
#define ull unsigned ll
#define i128 __int128
using namespace std;
namespace qiqi {
const int inf = 1e9;
void main() {
string s,t;
cin >> s >> t;
int n = sz(s),m = sz(t);
vector<vi> lcp(n+1,vi(m+1));
for (int i = n-1; i >= 0; i--) {
for (int j = m-1; j >= 0; j--) {
lcp[i][j] = s[i] == t[j] ? lcp[i+1][j+1]+1 : 0;
}
}
int ans = n; pii pans({});
vector<vi> f(n+1,vi(m+1,inf));
vector<vector<pii>> g(n+1,vector<pii>(m+1));
for (int i = 0; i <= lcp[0][0]; i++) {
f[i][i] = i+1; g[i][i] = pii(0,0);
}
for (int i = 1; i < n; i++) {
for (int j = 0; j < m; j++) {
if (f[i][j] > f[i-1][j]) {
f[i][j] = f[i-1][j];
g[i][j] = pii(i-1,j);
}
}
for (int j = 1; j < n-i; j++) {
int lst = -1;
for (int k = 0; k <= m-j; k++) {
if (lcp[i][k] >= j) {
for (int o = lst+1; o <= k; o++) {
if (f[i+j][k+j] > f[i][o]+j+1) {
f[i+j][k+j] = f[i][o]+j+1;
g[i+j][k+j] = pii(i,o);
}
}
lst = k;
}
}
for (int o = lst+1; o <= m; o++) {
if (ans > f[i][o]+j+1) {
ans = f[i][o]+j+1;
pans = pii(i,o);
}
}
}
int len = n-i;
for (int j = lcp[i][m-len] != len ? 0 : m-len+1; j <= m; j++) {
if (ans > f[i][j]+len) {
ans = f[i][j]+len;
pans = pii(i,j);
}
}
}
if (ans == n) {
cout << s << '\n';
return;
}
vector<string> vec;
auto [p,q] = pans;
int k = ans;
if (p+k-f[p][q] != n) {
vec.eb("*");
k--;
}
while (k) {
vec.eb(string(s.begin()+p,s.begin()+p+k-f[p][q]));
k = f[p][q];
if (p) {
vec.eb("*");
k--;
}
while (p && g[p][q].se == q) {
tie(p,q) = g[p][q];
}
tie(p,q) = g[p][q];
}
reverse(all(vec));
string sans;
for (const auto &str:vec) {
sans += str;
}
cout << sans << '\n';
}
}
int main() {
// clock_t st = clock();
// freopen("test.in","r",stdin);
// freopen("test.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
// cin >> T;
while (T--) {
qiqi::main();
}
// cout << (double)(clock()-st)/CLOCKS_PER_SEC;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3608kb
input:
aabb ab
output:
*bb
result:
ok correct
Test #2:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
abaabaaabbbaabbb abaabbbaabaaabbb
output:
*baabbb
result:
ok correct
Test #3:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
amuletofyendor amuletofshmendor
output:
*y*
result:
ok correct
Test #4:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
spbau spbsu
output:
*au
result:
ok correct
Test #5:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
b abaabaaaabaababbabba
output:
b
result:
ok correct
Test #6:
score: 0
Accepted
time: 0ms
memory: 3516kb
input:
bbaabaaa babbaabbbbababbaaab
output:
*a
result:
ok correct
Test #7:
score: -100
Wrong Answer
time: 0ms
memory: 3568kb
input:
abb baabababababbbb
output:
abb
result:
wrong answer jury has better answer