QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#291768 | #5312. Levenshtein Distance | Radewoosh# | WA | 1770ms | 19768kb | C++23 | 3.8kb | 2023-12-27 06:18:55 | 2023-12-27 06:18:56 |
Judging History
answer
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC target ("avx2")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define shandom_ruffle random_shuffle
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax=100*1007;
const int d=17;
const int kax=107;
int k, n, m;
char raz[nax];
char dwa[nax];
int hasz1[d][nax];
int hasz2[d][nax];
int wyn[nax];
int wsp(int a, int b)
{
int ret=0;
for (int i=d-1; i>=0; i--)
{
if (hasz1[i][a]==hasz2[i][b])
{
ret+=(1<<i);
a+=(1<<i);
b+=(1<<i);
}
}
return ret;
}
int dp[kax][kax];
int czas;
void maxi(int &a, int b)
{
a=max(a, b);
}
int &daj(int a, int b)
{
return dp[a][b+a];
}
void cons(int ile, int a, int b, int h)
{
if (a<0 || b<h || a>n || b>m)
return;
maxi(daj(ile, a-(b-h)), a);
}
int ost[nax];
int main()
{
scanf("%d", &k);
scanf("%s", raz+1);
scanf("%s", dwa+1);
n=strlen(raz+1);
m=strlen(dwa+1);
for (int i=1; i<=n; i++)
hasz1[0][i]=raz[i];
for (int i=1; i<=m; i++)
hasz2[0][i]=dwa[i];
hasz1[0][n+1]=300;
hasz2[0][m+1]=400;
for (int h=1; h<d; h++)
{
vector<pair<pii,pii>> wek;
int dlu=(1<<h);
for (int i=1; i<=n+1; i++)
{
czas++;
if (i+dlu-1<=n)
wek.push_back({{hasz1[h-1][i], hasz1[h-1][i+dlu/2]}, {1, i}});
else
wek.push_back({{czas, czas}, {1, i}});
}
for (int i=1; i<=m+1; i++)
{
czas++;
if (i+dlu-1<=m)
wek.push_back({{hasz2[h-1][i], hasz2[h-1][i+dlu/2]}, {2, i}});
else
wek.push_back({{czas, czas}, {2, i}});
}
sort(wek.begin(), wek.end());
int num=0;
for (int i=0; i<(int)wek.size(); i++)
{
if (!i || wek[i].first!=wek[i-1].first)
num++;
if (wek[i].second.first==1)
hasz1[h][wek[i].second.second]=num;
else
hasz2[h][wek[i].second.second]=num;
}
}
czas=0;
for (int h=0; h<m; h++)
{
czas++;
for (int i=0; i<=k; i++)
for (int j=0; j<=2*i; j++)
dp[i][j]=-1;
dp[0][0]=0;
for (int i=0; i<=k; i++)
{
for (int j=-i; j<=i; j++)
{
int &w=daj(i, j);
if (w<0)
continue;
int a=w;
int b=w+h-j;
int p=wsp(a+1, b+1);
w+=p;
a+=p;
b+=p;
for (int x=-1; x<=1; x++)
for (int y=-1; y<=1; y++)
if (abs(x-y)!=2)
cons(i+1, a+x, b+y, h);
if (a==n && b>h && ost[b]<czas)
{
ost[b]=czas;
wyn[i]++;
}
}
}
}
for (int i=0; i<=k; i++)
printf("%d\n", wyn[i]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 16064kb
input:
4 aaa aabbaab
output:
0 5 15 7 1
result:
ok 5 number(s): "0 5 15 7 1"
Test #2:
score: 0
Accepted
time: 991ms
memory: 19768kb
input:
30 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
ok 31 numbers
Test #3:
score: 0
Accepted
time: 1155ms
memory: 19236kb
input:
30 BBAAABAABBBA ABBABBBBAABAAAABABBBAABAABBAABAAAAAABAABABBAAAABAAAAABABAABAABBABBAAAABBBBAABBABAAABAABAABBBBBABBABABBBBABBBBAAABBABABBBBAAABBBBAAAABABABABABABABAAABBBBBAABAABAABBAABBBAABBBBBBBABAABAABAABABAABAAABAABBBAABABBABBAAABAAAABABABBABBBAAABBBAAAABBBBABABABAABAABBBBBBBBBAABBBABABBBABAABBABBA...
output:
17 662 8230 50302 166666 310121 345469 280387 227200 209178 203013 198561 105117 102147 99771 97730 96058 94730 93633 92720 92060 91525 91143 90831 90585 90419 90288 90200 90120 90068 90035
result:
ok 31 numbers
Test #4:
score: 0
Accepted
time: 1539ms
memory: 19644kb
input:
30 AAABBAAAAAAAAAAAAABAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAABAAAAABAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABABAAAABAAAABAAAABAAAAABAAAAAABAAAAAAAAABAAABAAABBAAAAAAAAAAAAAAAABAABAAABAAAAAAAAAAAAABAAAAAAAAAAAAAAAABAAABBAAAAAAAAAAAAAAAAAAAAAAAAAABAABAABABAAAAAAAAAAAAAAA...
output:
0 0 0 0 1 28 263 1410 6434 22523 56017 115080 189633 263874 316906 339254 332825 312943 286470 263283 246310 235032 227182 221294 216978 213734 211178 208848 206945 205393 204279
result:
ok 31 numbers
Test #5:
score: 0
Accepted
time: 1229ms
memory: 19304kb
input:
30 ABABAABAAABAAAA AABBABABBBBBAAABABAABBAAABBBAABABBBABABABABABBABBBAAAAABBAAABBABABABABABBAAABBAAABAAABBBBBBBAABABBBAAAAABAABBBABBABBBABBBABABAABABBBAAABBABBAAABBBBBBBAABAABABAAAAAABBAABAAABBBAABBAABBAABBABABAAAAAAAABBBBBAAABABABBABAAAAABAABAABAABAABAAABABBABBBABAAABBBABABAABAABBBAABABBAABBAAAABAB...
output:
2 125 1938 15793 70756 178090 282937 325020 310617 277899 244094 217672 206966 202456 198644 105535 102767 100355 98411 96655 95310 94124 93217 92487 91872 91414 91039 90741 90555 90397 90276
result:
ok 31 numbers
Test #6:
score: 0
Accepted
time: 1404ms
memory: 19544kb
input:
30 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...
output:
0 0 0 0 1 91 1082 14598 58877 123681 212928 258264 253856 277926 265254 243456 217809 198008 190004 184665 184470 183593 183524 183406 183335 183255 183185 183142 183078 182991 182922
result:
ok 31 numbers
Test #7:
score: 0
Accepted
time: 1301ms
memory: 18936kb
input:
30 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAABABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...
output:
1 460 44032 126686 201431 222795 213509 199190 187254 184699 184159 183907 183818 183558 183500 183466 183412 183393 183343 183299 183275 183236 183163 183127 183105 183056 183010 182971 182910 182719 182437
result:
ok 31 numbers
Test #8:
score: 0
Accepted
time: 1290ms
memory: 19344kb
input:
30 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...
output:
29 25121 100687 175758 199099 210112 187931 180903 178707 178497 178494 178497 178495 178496 178492 178492 178492 178491 178490 178491 178490 178490 178492 178489 178489 178488 178487 178487 178487 178488 178487
result:
ok 31 numbers
Test #9:
score: 0
Accepted
time: 1307ms
memory: 18952kb
input:
30 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...
output:
17 12879 77552 170649 187824 198210 200962 189247 181730 180843 178608 178607 178607 178605 178599 178599 178599 178596 178595 178592 178594 178595 178593 178594 178593 178595 178593 178593 178594 178593 178591
result:
ok 31 numbers
Test #10:
score: 0
Accepted
time: 1413ms
memory: 19368kb
input:
30 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...
output:
0 0 0 0 73 320 52858 125690 177498 270124 217932 192611 177148 228465 180709 166240 162360 162360 162359 162359 162359 162359 162358 162358 162359 162357 162357 162357 162357 162358 162358
result:
ok 31 numbers
Test #11:
score: 0
Accepted
time: 1436ms
memory: 19012kb
input:
30 ABBABABABAAABAAAAAAABAAABBAAAA BABBABBBAAABBAAAAABBBBBAAAABAAAAAABBAABAAAABAAABAAAAAAAABAAABAABAABAABBBAAAABAAAABABBABBAAABABAAAAAAAABAABBAAAAAABABAAAAABABAAAAAAABAAAAAAAABAAABBBAAAAABAABAABAAAAABAAAAAAAAAAAABABAAAABABAAAABAABBAAAAABBAAABABBBBBBAABABAAAAABABBBAABABBAAAABAAAAABABABBAAAAAAAABABBBAB...
output:
0 0 1 38 617 4567 22647 76780 180046 296249 362349 361655 325883 289074 263906 246552 233312 221488 212319 205320 200921 198057 196229 194923 193749 192649 191581 190728 189773 188925 98116
result:
ok 31 numbers
Test #12:
score: 0
Accepted
time: 1069ms
memory: 19304kb
input:
30 Y3YYY wwwwwwwYYwwwww3ww3w33Yww3wYY3w3w33w3Y3YY33wYwY33wwYwY33Y3w3wwwY333ww333Ywww3w3Y33wwYw3YYwY3Y3w33YwwwwwYYYw3YYYYYYww3w3333Yw3Y3wY3wYw3w3w3Y3w33YY33YwwY3Y3wY33w3333Yw333wYYw3Yw33w3YwYYYYYwwwwY3wwYYYYY33Y3YwYY3Yw3www3Ywww333w3YYY333YY3Y3333Y3Y33ww33333wwYY3YYYww3YYYYYYwwYYYwwYY33Y33wYY3w3wY3w3...
output:
412 9896 68598 212288 338054 201716 131998 125202 120710 117075 114099 111708 109603 107820 106320 105086 104074 103198 102592 102094 101640 101290 101006 100767 100571 100430 100305 100226 100158 100109 100074
result:
ok 31 numbers
Test #13:
score: -100
Wrong Answer
time: 1770ms
memory: 19700kb
input:
30 BnAnnBB3fn33BffBBn3nfAABnBnfBfffBfBAf3Ann3nnfAnAAA 3Bn33ABnBnn3ffnfnnn3fB3Af33fBf3fnnBnBAAffBB33BnB3A3nBAnnABnf33AAAB3nnBA33nf33n3nBfnfnfABB3nBAA3ABAnAAB33A33ABfnAnA33f3fBBnBBfBnB3f3BBf3AAfBAAB3A3BnffBnf33nnffA33fAnffnBBB3nnBBfnBB33BffABn3n3BnAffBBA3nnnAfBfBnn3nn3fn3fn3B3AB3fBn3ABf3BAfAnAB3AAABB3...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 71 367 1634 6100 19609 52887 124364 249174 415281
result:
wrong answer 24th numbers differ - expected: '377', found: '367'