QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#291766#5312. Levenshtein DistanceRadewoosh#RE 3ms15940kbC++234.1kb2023-12-27 05:55:072023-12-27 05:55:07

Judging History

你现在查看的是最新测评结果

  • [2023-12-27 05:55:07]
  • 评测
  • 测评结果:RE
  • 用时:3ms
  • 内存:15940kb
  • [2023-12-27 05:55:07]
  • 提交

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);
		}
	}
	assert(ret<100);
	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++)
			{
				//~ debug() << imie(h) << imie(i) << imie(j);
				int &w=daj(i, j);
				if (w<0)
					continue;
				int a=w;
				int b=w+h-j;
				//~ debug() << imie(a) << imie(b);
				int x=wsp(a+1, b+1);
				w+=x;
				a+=x;
				b+=x;
				
				//~ debug() << i << " " << a << " " << b;
				for (int x=-1; x<=1; x++)
					for (int y=-1; y<=1; y++)
						cons(i+1, a+x, b+y, h);
				//~ maxi(daj(i+1, j-1), w);
				//~ maxi(daj(i+1, j), w);
				//~ maxi(daj(i+1, j+1), w);
				//~ debug() << i << " " << a << " " << b;
				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: 3ms
memory: 15940kb

input:

4
aaa
aabbaab

output:

0
5
15
7
1

result:

ok 5 number(s): "0 5 15 7 1"

Test #2:

score: -100
Runtime Error

input:

30
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...

output:


result: