QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#280638#7780. Dark LaTeX vs. Light LaTeXucup-team1303#ML 2ms14664kbC++202.5kb2023-12-09 17:23:262023-12-09 17:23:28

Judging History

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

  • [2024-11-25 20:53:52]
  • hack成功,自动添加数据
  • (/hack/1258)
  • [2023-12-09 17:23:28]
  • 评测
  • 测评结果:ML
  • 用时:2ms
  • 内存:14664kb
  • [2023-12-09 17:23:26]
  • 提交

answer

// MagicDark
#include <bits/stdc++.h>
#define debug cerr << "[" << __LINE__ << "] "
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> inline void chkmax(T& x, T y) {x = max(x, y);}
template <typename T> inline void chkmin(T& x, T y) {x = min(x, y);}
template <typename T> inline void read(T &x) {
	x = 0; int f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	x *= f;
}
const int N = 5010;
string s, t;
int lcpst1[N][N], lcpst2[N][N], lcpst[N][N], lcps[N][N], lcpt[N][N], occs[N][N], occt[N][N];
ll sss[N][N], sst[N][N], ans;
signed main() {
	cin.tie(0) -> sync_with_stdio(0);
	cin >> s >> t;
	int n = s.size(), m = t.size();
	s = ' ' + s, t = ' ' + t;
	F(i, 1, n) {
		DF(j, m, 1) {
			if (s[i] == t[j]) lcpst[i][j] = lcpst[i - 1][j + 1] + 1;
		}
	}
	DF(i, n, 1) {
		DF(j, m, 1) {
			if (s[i] == t[j]) lcpst1[i][j] = lcpst1[i + 1][j + 1] + 1;
		}
	}
	F(i, 1, n) {
		F(j, 1, m) {
			if (s[i] == t[j]) lcpst2[i][j] = lcpst2[i - 1][j - 1] + 1;
		}
	}
	DF(i, n, 1) {
		DF(j, n, 1) {
			if (s[i] == s[j]) lcps[i][j] = lcps[i + 1][j + 1] + 1;
		}
	}
	F(i, 1, m) {
		F(j, 1, m) {
			if (t[i] == t[j]) lcpt[i][j] = lcpt[i - 1][j - 1] + 1;
		}
	}
	F(i, 1, n) {
		F(j, 1, m) {
			occs[i][1]++;
			occs[i][lcpst2[i][j] + 1]--;
		}
		F(j, 1, n) {
			occs[i][j] += occs[i][j - 1];
			sss[i][j] = sss[i][j - 1] + occs[i][j];
		}
		// debug << i << " " << occs[i][1] << endl;
		// debug << occs[i][2] << endl;
	}
	F(i, 1, m) {
		F(j, 1, n) {
			occt[i][1]++;
			// debug << j << " " << i << " " << lcpst[j][i] << endl;
			occt[i][lcpst1[j][i] + 1]--;
		}
		F(j, 1, m) {
			occt[i][j] += occt[i][j - 1];
			sst[i][j] = sst[i][j - 1] + occt[i][j];
		}
		// debug << occt[i][1] << endl;
		// debug << occt[i][2] << endl;
	}
	F(i, 1, n)
		F(j, i, n) {
			int len = min(j - i, lcps[i][j + 1]);
			ans += sss[j][j - i + 1] - sss[j][j - i + 1 - len - 1];
			// debug << i << " " << j << " " << len << " " << ans << " " << j - i + 1 << endl;
		}
	// debug << ans << endl;
	F(i, 1, m)
		F(j, i, m) {
			int len = min(j - i, lcpt[i - 1][j]);
			if (!len) continue;
			ans += sst[i][j - i] - sst[i][j - i + 1 - len - 1];
		}
	cout << ans;
	return 0;
}
/* why?
*/

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 7824kb

input:

abab
ab

output:

8

result:

ok 1 number(s): "8"

Test #2:

score: 0
Accepted
time: 1ms
memory: 10072kb

input:

abab
abaaab

output:

29

result:

ok 1 number(s): "29"

Test #3:

score: 0
Accepted
time: 2ms
memory: 9900kb

input:

abcd
abcde

output:

10

result:

ok 1 number(s): "10"

Test #4:

score: 0
Accepted
time: 1ms
memory: 10128kb

input:

aaba
ba

output:

6

result:

ok 1 number(s): "6"

Test #5:

score: 0
Accepted
time: 0ms
memory: 14664kb

input:

babababaaabbaabababbbaabbbababbaaaaa
aaaabbaababbab

output:

1161

result:

ok 1 number(s): "1161"

Test #6:

score: -100
Memory Limit Exceeded

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

78156256250000

result: