QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#122776 | #6567. Repetitive String Invention | cada_dia_mas_insanos | WA | 389ms | 3420kb | C++17 | 2.7kb | 2023-07-11 03:14:33 | 2023-07-11 03:14:36 |
Judging History
answer
// Too many mind, no mind.
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <array>
#include <iomanip>
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define COMP(x) sort(ALL(x)); x.resize(unique(ALL(x)) - (x).begin())
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
using pii = pair <int, int>;
using vi = vector <int>;
using vpi = vector <pii>;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using ld = long double;
using vld = vector<ld>;
const int maxn = 810, P=31;
const ll mod[2] = {(ll)1e9+7, (ll)1e9+9};
ll add(ll a, ll b, int m) { return a + b >= mod[m] ? a + b - mod[m] : a + b; }
ll sub(ll a, ll b, int m) { return a >= b ? a - b : a - b + mod[m]; }
ll mul(ll a, ll b, int m) { return a*b%mod[m]; }
ll val[maxn];
ll pw[2][maxn];
ll lcp[maxn][maxn];
ll h[2][maxn];
int n;
char s[maxn];
void roll() {
pw[0][0] = pw[1][0] = 1;
fore(i, 1, maxn-1) {
forn(j, 2) pw[j][i] = mul(pw[j][i-1], P, j);
}
forn(i, n) {
forn(j, 2) {
h[j][i] = mul(s[i] - 'a' + 1, pw[j][i], j);
if (i) h[j][i] = add(h[j][i], h[j][i-1], j);
}
}
}
ll get(int l, int r) {
vl hash(2);
forn(j, 2) {
hash[j] = h[j][r];
if (l) hash[j] = sub(hash[j], h[j][l-1], j);
hash[j] = mul(hash[j], pw[j][maxn-1-r], j);
}
return hash[0] << 32 | hash[1];
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
cin >> s;
n = strlen(s);
roll();
int ans = 0;
forn(i, n) fore(j, i, n-1) {
ll cur = get(i, j);
int len=j-i+1;
forn(k, n) val[k]=0;
for(int k=j+1; k+len-1 < n; k++) ans += get(k, k+len-1) == cur;
int have = 0;
for(int k=0; k+len-1 < i; k++) {
val[k] = get(k, k+len-1) == cur;
have += val[k];
}
for(int k=j+1; k+len-1 < n; k++) {
val[k] = get(k, k+len-1) == cur;
have += val[k];
}
for (int w=1, l=i-1, r=j+1; w <= min(i, n-j-1); w++) {
if (get(i-w, i-1) != get(j+1, j+w)) continue;
while (l >= 0 && l+len-1 >= i-w) {
have -= val[l];
l--;
}
while (r < n && r-len+1 <= j+w) {
have -= val[r];
r++;
}
ans += have;
}
}
cout << ans << endl;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3420kb
input:
aaaa
output:
9
result:
ok single line: '9'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3400kb
input:
axabxbcxcdxd
output:
22
result:
ok single line: '22'
Test #3:
score: -100
Wrong Answer
time: 389ms
memory: 3420kb
input:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
output:
448448889
result:
wrong answer 1st lines differ - expected: '536006700', found: '448448889'