QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#280661 | #7780. Dark LaTeX vs. Light LaTeX | ucup-team1303# | WA | 326ms | 395876kb | C++20 | 2.9kb | 2023-12-09 17:29:13 | 2023-12-09 17:29:16 |
Judging History
answer
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,fma")
// 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;
}
bool be;
const int N = 5010;
string s, t;
int lcpst1[N][N], lcpst2[N][N], sss[N][N], sst[N][N], ans;
bool ed;
signed main() {
cin.tie(0) -> sync_with_stdio(0);
debug << (abs(&ed - &be)) / 1024 / 1024 << endl;
cin >> s >> t;
int n = s.size(), m = t.size();
s = ' ' + s, t = ' ' + t;
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) {
sss[i][1]++;
sss[i][lcpst2[i][j] + 1]--;
}
int cur = 0;
F(j, 1, n) {
cur += sss[i][j];
sss[i][j] = sss[i][j - 1] + cur;
}
// debug << i << " " << occs[i][1] << endl;
// debug << occs[i][2] << endl;
}
F(i, 1, m) {
F(j, 1, n) {
sst[i][1]++;
// debug << j << " " << i << " " << lcpst[j][i] << endl;
sst[i][lcpst1[j][i] + 1]--;
}
int cur = 0;
F(j, 1, m) {
cur += sst[i][j];
sst[i][j] = sst[i][j - 1] + cur;
}
// debug << occt[i][1] << endl;
// debug << occt[i][2] << endl;
}
ms(lcpst1, 0);
ms(lcpst2, 0);
DF(i, n, 1) {
DF(j, n, 1) {
if (s[i] == s[j]) lcpst1[i][j] = lcpst1[i + 1][j + 1] + 1;
}
}
F(i, 1, m) {
F(j, 1, m) {
if (t[i] == t[j]) lcpst2[i][j] = lcpst2[i - 1][j - 1] + 1;
}
}
F(i, 1, n)
F(j, i, n) {
int len = min(j - i, lcpst1[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, lcpst2[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: 19ms
memory: 201972kb
input:
abab ab
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 4ms
memory: 201772kb
input:
abab abaaab
output:
29
result:
ok 1 number(s): "29"
Test #3:
score: 0
Accepted
time: 11ms
memory: 201752kb
input:
abcd abcde
output:
10
result:
ok 1 number(s): "10"
Test #4:
score: 0
Accepted
time: 15ms
memory: 201804kb
input:
aaba ba
output:
6
result:
ok 1 number(s): "6"
Test #5:
score: 0
Accepted
time: 0ms
memory: 205940kb
input:
babababaaabbaabababbbaabbbababbaaaaa aaaabbaababbab
output:
1161
result:
ok 1 number(s): "1161"
Test #6:
score: -100
Wrong Answer
time: 326ms
memory: 395876kb
input:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
736364688
result:
wrong answer 1st numbers differ - expected: '78156256250000', found: '736364688'