QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#291767 | #5312. Levenshtein Distance | Radewoosh# | WA | 1367ms | 19652kb | C++23 | 3.8kb | 2023-12-27 05:58:05 | 2023-12-27 05:58:05 |
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 x=wsp(a+1, b+1);
w+=x;
a+=x;
b+=x;
for (int x=-1; x<=1; x++)
for (int y=-1; y<=1; y++)
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: 16080kb
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: 1145ms
memory: 19652kb
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: -100
Wrong Answer
time: 1367ms
memory: 18992kb
input:
30 BBAAABAABBBA ABBABBBBAABAAAABABBBAABAABBAABAAAAAABAABABBAAAABAAAAABABAABAABBABBAAAABBBBAABBABAAABAABAABBBBBABBABABBBBABBBBAAABBABABBBBAAABBBBAAAABABABABABABABAAABBBBBAABAABAABBAABBBAABBBBBBBABAABAABAABABAABAAABAABBBAABABBABBAAABAAAABABABBABBBAAABBBAAAABBBBABABABAABAABBBBBBBBBAABBBABABBBABAABBABBA...
output:
17 662 10355 70902 225833 364720 342389 261357 217352 198929 189016 184263 91995 90959 90466 90215 90091 90025 89995 89982 89977 89970 89968 89967 89965 89964 89963 89962 89961 89960 89959
result:
wrong answer 3rd numbers differ - expected: '8230', found: '10355'