QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#186015 | #5065. Beautiful String | ykpcx | WA | 168ms | 199376kb | C++17 | 1.3kb | 2023-09-22 23:23:38 | 2023-09-22 23:23:39 |
Judging History
answer
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <bitset>
using namespace std;
using ll = long long;
const int N = 5e3 + 5;
int n;
char s[N];
int lcp[N][N];
int sum[N][N];
void init() {
for (int i = 0; i < n; i++) {
fill(sum[i], sum[i] + n + 1, 0);
fill(lcp[i], lcp[i] + n, 0);
}
for (int i = n; i--; ) {
for (int j = n; j--;) {
if (s[i] == s[j]) lcp[i][j] = lcp[i+1][j+1] + 1;
}
}
}
inline int get_sum(int i, int l, int r) {
return sum[i][r] - sum[i][l-1];
}
void solve() {
cin >> s;
n = strlen(s);
init();
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
int p = min(lcp[i][j], j-i-1);
if (p) {
sum[i][1]++;
sum[i][p+1]--;
}
}
for (int j = 1; j <= n; j++) {
sum[i][j] += sum[i][j-1];
}
for (int j = 1; j <= n; j++) {
sum[i][j] += sum[i][j-1];
}
}
int cnt = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (lcp[i][j] < j - i) continue;
int a = j - i;
cnt += get_sum(j, a + 1, n);
}
}
printf("%d\n", cnt);
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
int t; cin >> t; while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5892kb
input:
2 114514 0000000
output:
1 3
result:
ok 2 number(s): "1 3"
Test #2:
score: 0
Accepted
time: 76ms
memory: 199376kb
input:
11 79380 2483905227 37902399703986576270 39991723655814713848046032694137883815354365954917 5541883522667841718787744915558298207485830622522715211018760095628594390563630840464643840093757297 56530485554219245862513973750218715585679416120445975390556326891488719311495909340757506478400624741858999...
output:
0 0 0 2 4 20 119 113 1086 2128 15166
result:
ok 11 numbers
Test #3:
score: 0
Accepted
time: 3ms
memory: 14088kb
input:
50 11111111111111111111111111111111111111121111111111111111111111111111111111111112111111111121111111111211111121211121111111111111111111111111111211121111111111111111111111111111111111111111111111111112 111111111111111111111111111111111111111111111121111121111111111111111111111111111111111111111111...
output:
779344 799116 716078 723215 1197647 403357 652134 625671 414294 942493 390998 793444 612061 507395 473508 836065 461623 374925 539333 592574 676408 610940 463761 490048 995917 595830 424894 332669 596834 655095 521489 1032050 697420 752056 406316 360973 1180943 948628 478572 1026603 711224 429752 49...
result:
ok 50 numbers
Test #4:
score: 0
Accepted
time: 3ms
memory: 14052kb
input:
50 11211121122222111222111111222112111221112111121112221111111121211111212211212122112212221221112112221221112211211112121222112221211122112211112111112112211121222111222212211121111111112111112121111122 112112121211212111212221221222211211121212221111112122121211112221221121121112111221211112122121...
output:
7499 6375 7041 7889 6622 6804 8695 8795 7018 8387 8910 8019 8223 8820 7324 7144 8035 9941 7073 7373 7427 7280 6946 8204 7931 6769 7050 9268 7682 8232 7797 7356 7012 8967 7469 6869 11728 6562 7604 8840 7885 8658 7006 8156 10694 6716 6121 7499 7456 7981
result:
ok 50 numbers
Test #5:
score: -100
Wrong Answer
time: 168ms
memory: 84684kb
input:
15 111111111111111111111111111111111111111111111111111111111111121111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111211111111111111111111111111111111111111111111111...
output:
-1978378306 -142299245 56298360 -345762305 -1742858749 769356532 1523854696 892430452 1907882095 -1489234842 236758666 714533246 1101820191 -360214600 1788248324
result:
wrong answer 1st numbers differ - expected: '6611556286', found: '-1978378306'