QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#399079#5312. Levenshtein DistancedefinierenRE 0ms0kbC++176.1kb2024-04-25 21:38:232024-04-25 21:38:30

Judging History

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

  • [2024-04-25 21:38:30]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-04-25 21:38:23]
  • 提交

answer

#include <bits/stdc++.h>

#define fir first
#define sec second
#ifdef LOCAL
#define dbg(x) cerr << "In Line " << __LINE__ << " the " << #x << " = " << x << '\n';
#define dpi(x, y) cerr << "In Line " << __LINE__ << " the " << #x << " = " << x << " ; " << "the " << #y << " = " << y << '\n';
#define dbgf(fmt, args...) fprintf(stderr, fmt, ##args);
#else
#define dbg(x) void();
#define dpi(x, y) void();
#define dbgf(fmt, args...) void();
#endif

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i128 = __int128_t;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using vi = vector<int>;
using vpii = vector<pii>;

bool Mbe;
constexpr int MOD = 998244353;
template<typename T> T add(T a, T b, T p = MOD) { return (a + b >= p) ? (a + b - p) : (a + b); }
template<typename T> T del(T a, T b, T p = MOD) { return (a - b < 0) ? (a - b + p) : (a - b); }
template<typename T> T mul(T a, T b, T p = MOD) { return 1ll * a * b % p; }
template<typename T> T cadd(T &a, T b, T p = MOD) { return a = add(a, b, p); }
template<typename T> T cdel(T &a, T b, T p = MOD) { return a = del(a, b, p); }
template<typename T> T cmul(T &a, T b, T p = MOD) { return a = mul(a, b, p); }
template<typename T> T cmax(T &a, T b) { return a = max(a, b); }
template<typename T> T cmin(T &a, T b) { return a = min(a, b); }

namespace FastIO {
	constexpr int LEN = 1 << 20;
	char in[LEN + 1], out[LEN + 1];
	char *pin = in, *pout = out, *ein = in, *eout = out + LEN;

	char gc() { return pin == ein && (ein = (pin = in) + fread(in, 1, LEN, stdin), ein == in) ? EOF : *pin ++; }
	void pc(char c) { pout == eout && (fwrite(out, 1, LEN, stdout), pout = out); (*pout ++) = c; return; }
	void Flush() { fwrite(out, 1, pout - out, stdout); pout = out; }

	template<typename T> T Read() {
		T x = 0; int f = 1; char ch = gc();
		while (ch < '0' || ch > '9') f = (ch == '-' ? (~f + 1) : f), ch = gc();
		while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = gc();
		return x * f;
	}
	template<typename T> void Write(T x, char c) {
		static char stk[40]; int tp = 0;
		if (x < 0) pc('-'), x = ~x + 1;
		do stk[tp++] = x % 10 + 48, x /= 10; while (x);
		while (tp --) pc(stk[tp]); pc(c); return;
	}
	void Read(char *s) {
		char ch = gc();
		while (!((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') ||
			(ch >= '0' && ch <= '9'))) ch = gc();
		while ((ch != EOF) && ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') ||
			(ch >= '0' && ch <= '9'))) *s = ch, s ++, ch = gc();
		*s = '\0'; return;
	}
	void Write(char *s) {
		while (*s != '\0') pc(*s), s ++; return;
	}
	void Puts(char *s) {
		Write(s), pc('\n'); return;
	}
}

#define getchar FastIO::gc
#define putchar FastIO::pc
#define Flush FastIO::Flush
#define Read FastIO::Read
#define Write FastIO::Write
#define Puts FastIO::Puts

constexpr int MAXN = 1e5 + 5, MAXK = 35, MAXLG = 18;
int n, m, k, f[MAXK][MAXK << 1], ans[MAXK], dis[MAXN];
char s[MAXN], t[MAXN];

struct Suffix_Array {
	char s[MAXN << 1];
	int n, rk[MAXN << 1], sa[MAXN << 1], id[MAXN << 1], pid[MAXN << 1],
		ork[MAXN << 2], ht[MAXN << 1], st[MAXLG][MAXN << 1], bin[MAXN << 1];
	
	void Build(char _s[], char _t[]) {
		int ls = strlen(_s + 1), lt = strlen(_t + 1);
		n = ls + lt + 1; int m = (int)'z', p = 0;
		auto cmp = [&](int i, int j, int w) -> bool
			{ return ork[i] == ork[j] && ork[i + w] == ork[j + w]; };
		for (int i = 1; i <= ls; i ++) s[i] = _s[i]; s[ls + 1] = ' ';
		for (int i = 1; i <= lt; i ++) s[ls + 1 + i] = _t[i];
		for (int i = 1; i <= n; i ++) bin[rk[i] = s[i]] ++;
		for (int i = 1; i <= m; i ++) bin[i] += bin[i - 1];
		for (int i = n; i >= 1; i --) sa[bin[rk[i]] --] = i;
		for (int w = 1; ; w <<= 1, m = p, p = 0) {
			for (int i = n; i > n - w; i --) id[++ p] = i;
			for (int i = 1; i <= n; i ++) if (sa[i] > w) id[++ p] = sa[i] - w;
			for (int i = 1; i <= m; i ++) bin[i] = 0;
			for (int i = 1; i <= n; i ++) bin[pid[i] = rk[id[i]]] ++;
			for (int i = 1; i <= m; i ++) bin[i] += bin[i - 1];
			for (int i = n; i >= 1; i --) sa[bin[pid[i]] --] = id[i];
			for (int i = 1; i <= n; i ++) ork[i] = rk[i]; p = 0;
			for (int i = 1; i <= n; i ++) rk[sa[i]] = cmp(sa[i - 1], sa[i], w) ? p : ++ p;
			if (p == n) break;
		}
		for (int i = 1, j = 0; i <= n; i ++, j -= !!j) {
			while (s[i + j] == s[sa[rk[i] - 1] + j]) j ++;
			st[0][rk[i]] = ht[rk[i]] = j;
		}
		for (int i = 1; i <= __lg(n); i ++)
			for (int j = 1; j + (1 << i) - 1 <= n; j ++)
				st[i][j] = min(st[i - 1][j], st[i - 1][j + (1 << i - 1)]);
		return;
	}
	int Query(int l, int r) {
		int k = __lg(r - l + 1);
		return min(st[k][l], st[k][r - (1 << k) + 1]);
	}
	int Get_Lcp(int i, int j) {
		if ((i = rk[i]) > (j = rk[j])) swap(i, j);
		return Query(i + 1, j);
	}
} sa;

int &F(int i, int j) {
	return f[i][j + k];
}

void slv() {
	scanf("%d\n%s\n%s", &k, s + 1, t + 1);
	sa.Build(s, t), n = strlen(s + 1), m = strlen(t + 1);
	for (int _ = 1; _ <= m; _ ++) {
		for (int i = 0; i <= k; i ++)
			for (int j = - i; j <= i; j ++)
				F(i, j) = -1;
		F(0, 0) = 0;
		for (int i = 0; i <= k; i ++)
			for (int j = - i; j <= i; j ++) if (~F(i, j)) {
				F(i, j) += sa.Get_Lcp(F(i, j) + 1, n + _ + F(i, j) + j);
				if (i ^ k) {
					cmax(F(i + 1, j + 1), F(i, j));
					cmax(F(i + 1, j), F(i, j) + 1);
					cmax(F(i + 1, j - 1), F(i, j) + 1);
				}
			}
		int l = max(_, _  + n - k - 1), r = min(m, _ + n + k - 1);
		for (int i = l; i <= r; i ++) dis[i] = k + 1;
		for (int i = 0; i <= k; i ++)
			for (int j = - i; j <= i; j ++) if (F(i, j) >= n)
				cmin(dis[min(m, _ + n + j - 1)], i);
		for (int i = l; i <= r; i ++) ans[dis[i]] ++;
	}
	for (int i = 0; i <= k; i ++)
		Write(ans[i], '\n');
	return;
}
void clr() {

	return;
}

bool Med;
int main() {
#ifdef LOCAL
	freopen("!in.in", "r", stdin);
	freopen("!out.out", "w", stdout);
	fprintf(stderr, "%.3lf Mb\n", fabs((&Mbe - &Med) / 1048576.0));
#endif
	int T = 1;
//	int T = Read<int>();
	while (T --) slv(), clr();
	Flush();
#ifdef LOCAL
	fprintf(stderr, "%d ms\n", (int)clock());
#endif
	return 0;
}

詳細信息

Test #1:

score: 0
Runtime Error

input:

4
aaa
aabbaab

output:


result: