QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#610163 | #7780. Dark LaTeX vs. Light LaTeX | 为什么要演奏春日影 (Jinyuan Deng)# | RE | 12ms | 199916kb | C++20 | 2.6kb | 2024-10-04 15:05:21 | 2024-10-04 15:05:22 |
Judging History
This is the latest submission verdict.
- [2024-11-25 20:53:52]
- hack成功,自动添加数据
- (/hack/1258)
- [2024-10-04 15:05:21]
- Submitted
answer
#include<bits/stdc++.h>
// #define int long long
#define ll long long
#define db double
#define i128 __int128_t
#define pii pair<int, int>
using namespace std;
const int maxn = 5e3 + 10;
struct exKMP {
int z[maxn];
void get_z(string& c) {
int len = c.length();
int p = 0, k = 1, l;
z[0] = len;
while (p + 1 < len && c[p] == c[p + 1])
p++;
z[1] = p;
for (int i = 2; i < len; i++) {
p = k + z[k] - 1;
l = z[i - k];
if (i + l <= p)
z[i] = l;
else {
int j = max(0, p - i + 1);
while (i + j < len && c[i + j] == c[j])
j++;
z[i] = j;
k = i;
}
}
}
} Z;
int sub[maxn][maxn];
int cnt[maxn][maxn];
void get_cnt(string s, string t) { // cnt[i][j] : S [i, j] 在 T 的出现次数
int n = s.length();
for (int i = 1; i <= n; i++) {
string tem = s.substr(i - 1) + '#' + t;
Z.get_z(tem);
for (int j = n - i + 2; j < tem.length(); j++) {
if (Z.z[j]) {
cnt[i][i]++;
cnt[i][i + Z.z[j]]--;
}
}
}
for (int i = 1; i <= n; i++)
for (int j = i; j <= n; j++)
cnt[i][j] += cnt[i][j - 1];
}
ll cal(string s, string t, int id) {
int n = s.length(), m = t.length();
ll ans = 0;
// cout << "same" << ans << endl;
get_cnt(s, t);
if (id == 0) {
for (int i = 1; i <= n; i++)
for (int j = i; j <= n; j++)
ans += cnt[i][j];
}
for (int i = 1; i <= n; i++) {
string str2 = s.substr(i - 1);
Z.get_z(str2);
for (int j = 3; j <= str2.length(); j++) {
int mxlen = min(Z.z[j - 1], j - 1);
if (!mxlen) continue;
// 右端点在 j - 1, 左端点在 2 到 mxlen + 1
sub[i - 1 + j - 1][i - 1 + 2]++;
sub[i - 1 + j - 1][i - 1 + mxlen + 1 + 1]--;
}
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= i; j++) {
sub[i][j] += sub[i][j - 1];
if (sub[i][j] > 0) {
ans += sub[i][j] * cnt[j][i];
// cout << "l, r = " << j << " " << i << endl;
}
}
return ans;
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
string s, t;
cin >> s >> t;
ll res = cal(s, t, 0);
memset(sub, 0, sizeof sub);
memset(cnt, 0, sizeof cnt);
res += cal(t, s, 1);
cout << res << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 199688kb
input:
abab ab
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 12ms
memory: 199916kb
input:
abab abaaab
output:
29
result:
ok 1 number(s): "29"
Test #3:
score: 0
Accepted
time: 11ms
memory: 199636kb
input:
abcd abcde
output:
10
result:
ok 1 number(s): "10"
Test #4:
score: 0
Accepted
time: 7ms
memory: 199616kb
input:
aaba ba
output:
6
result:
ok 1 number(s): "6"
Test #5:
score: 0
Accepted
time: 3ms
memory: 199708kb
input:
babababaaabbaabababbbaabbbababbaaaaa aaaabbaababbab
output:
1161
result:
ok 1 number(s): "1161"
Test #6:
score: -100
Runtime Error
input:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...