QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#112201 | #6567. Repetitive String Invention | maomao90# | RE | 0ms | 0kb | C++17 | 3.1kb | 2023-06-10 16:08:43 | 2023-06-10 16:09:06 |
Judging History
answer
// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define RREP(i, s, e) for (int i = (s); i >= (e); i--)
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define SZ(_a) (int) _a.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;
#ifndef DEBUG
#define cerr if (0) cerr
#endif
const int INF = 1000000005;
const ll LINF = 1000000000000000005ll;
const int MAXN = 805;
const int X = 31;
const int INVX = 128805723;
const int MOD = 998244353;
int n;
string s;
int pw[MAXN], ipw[MAXN];
int hsh[MAXN][MAXN];
unordered_map<int, int> mp[MAXN];
ll ans;
ll solve(bool z) {
ll res = 0;
REP (i, 0, n) {
mp[i].clear();
}
REP (i, 0, n) {
int chsh = 0;
REP (j, i, n) {
chsh = (chsh + (ll) pw[j - i] * (s[j] - 'a' + 1)) % MOD;
hsh[i][j] = chsh;
}
}
RREP (i, n - 2, 0) {
//int chsh = 0;
REP (j, i + 1, n) {
//chsh = (chsh + (ll) pw[j - i - 1] * (s[j] - 'a' + 1)) % MOD;
mp[j - i - 1][hsh[i + 1][j]]++;
}
//chsh = 0;
RREP (j, i, 0) {
//chsh = ((ll) chsh * X + (s[j] - 'a' + 1)) % MOD;
//int lhsh = chsh, rhsh = 0;
RREP (k, i, i + j >> 1) {
// 2 * (k - j + 1) > i - j + 1
// 2 * k - 2 * j + 2 > i - j + 1
// 2 * k > j + i - 1
// 2 * k >= j + i
if (k != i || z) {
if (hsh[j][j + i - k - 1] == hsh[k + 1][i]) {
res += mp[k - (j + i - k)][hsh[j + i - k][k]];
}
/*
int tmp = (ll) (lhsh - rhsh) * ipw[i - k] % MOD;
if (tmp < 0) {
tmp += MOD;
}
res += mp[tmp];
*/
}
/*
lhsh = (lhsh - (ll) pw[k - j] * (s[k] - 'a' + 1)) % MOD;
if (lhsh < 0) {
lhsh += MOD;
}
rhsh = ((ll) rhsh * X + (s[k] - 'a' + 1)) % MOD;
*/
}
}
}
cerr << res << '\n';
return res;
}
int main() {
#ifndef DEBUG
ios::sync_with_stdio(0), cin.tie(0);
#endif
cin >> s;
n = SZ(s);
pw[0] = ipw[0] = 1;
REP (i, 1, n) {
pw[i] = (ll) pw[i - 1] * X % MOD;
ipw[i] = (ll) ipw[i - 1] * INVX % MOD;
}
ans += solve(1);
reverse(ALL(s));
ans += solve(0);
cout << ans << '\n';
return 0;
}
詳細信息
Test #1:
score: 0
Runtime Error
input:
aaaa