QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#606680 | #5065. Beautiful String | AngelOlan | WA | 209ms | 199024kb | C++20 | 1.2kb | 2024-10-03 11:28:49 | 2024-10-03 11:28:49 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
// Pura Gente del Coach Moy
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
#define pb push_back
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define ROF(i, a, b) for (int i = (int)a - 1; i >= (int)b; --i)
#define ENDL '\n'
signed main() {
cin.tie(0)->sync_with_stdio(0);
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
int n = SZ(s);
vector<vi> lcp(n, vi(n + 1));
FOR (len, 1, n) {
ROF (i, n - len, 0) {
if (s[i] != s[i + len]) {
lcp[i][i + len] = 0;
continue;
}
lcp[i][i + len] = 1 + lcp[i + 1][i + len + 1];
if (lcp[i][i + len] == len + 1) --lcp[i][i + len];
}
}
vector<vi> p(n, vi(n));
FOR (i, 0, n) {
FOR (len, 1, i + 1) p[i][len] = lcp[i - len][i] == len;
FOR (len, 1, n) p[i][len] += p[i][len - 1];
}
ll ans = 0;
FOR (i, 0, n) FOR (j, i + 2, n) if (lcp[i][j] >= 2) {
int x = min(j - i - 2, lcp[i][j] - 1);
ans += p[i][x];
}
cout << ans << ENDL;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3620kb
input:
2 114514 0000000
output:
1 3
result:
ok 2 number(s): "1 3"
Test #2:
score: -100
Wrong Answer
time: 209ms
memory: 199024kb
input:
11 79380 2483905227 37902399703986576270 39991723655814713848046032694137883815354365954917 5541883522667841718787744915558298207485830622522715211018760095628594390563630840464643840093757297 56530485554219245862513973750218715585679416120445975390556326891488719311495909340757506478400624741858999...
output:
0 0 0 1 4 19 105 104 978 1932 13689
result:
wrong answer 4th numbers differ - expected: '2', found: '1'