QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#117429 | #6567. Repetitive String Invention | UNos_maricones# | WA | 55ms | 4132kb | C++20 | 1.7kb | 2023-07-01 07:58:37 | 2023-07-01 07:58:40 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "../debug.h"
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define pb push_back
const long long N = 1000;
vector <long long> z_algorithm (string &s) {
long long n = s.size();
vector <long long> z(n);
long long l = 0, r = 0;
for (long long i = 1; i < n; ++i) {
z[i] = max(0ll, min(z[i - l], r - i + 1));
while (i + z[i] < n && s[z[i]] == s[i + z[i]])
l = i, r = i + z[i], ++z[i];
}
return z;
}
vector <long long> zs[N];
long long solve (string s, long long flag) {
long long n = s.size();
for (long long i = 0; i < n; ++i) {
string cur = "";
for (long long j = i; j < n; ++j) cur.pb(s[j]);
zs[i] = z_algorithm(cur);
}
//cout << zs[0][6] << '\n';
long long ans = 0;
for (long long k = 0; k < n; ++k) {
for (long long i = k + flag; i < n; ++i) {
vector <long long> wh(n + 1, -1);
long long add = 0, x = 0;
long long mx = 0;
vector <long long> prf(n + 1, 0);
for (long long j = i + 1; j < n; ++j) {
if (zs[k][j - k] >= i - k) wh[j + i - k] = j - i;
while (mx <= wh[j]) {
if (mx) prf[mx] = prf[mx - 1] + 1;
mx++;
}
if (i == k) ans += min(j - i, zs[i][j-i]);
else if (mx)
ans += prf[min(zs[i][j-i], mx-1)];
//cout << " " << k << ' ' << i << ' '<< j <<' ' << zs[i][j-i] << ' ' << ans << '\n';
}
}
}
return ans;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
string s;
cin >> s;
string snw = s;
reverse(snw.begin(), snw.end());
cout << solve(s, 0) + solve(snw, 1) << '\n';
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3412kb
input:
aaaa
output:
9
result:
ok single line: '9'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3512kb
input:
axabxbcxcdxd
output:
22
result:
ok single line: '22'
Test #3:
score: 0
Accepted
time: 52ms
memory: 4132kb
input:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
output:
536006700
result:
ok single line: '536006700'
Test #4:
score: -100
Wrong Answer
time: 55ms
memory: 4096kb
input:
abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababab...
output:
268003400
result:
wrong answer 1st lines differ - expected: '136016600', found: '268003400'