QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#501485 | #7876. Cyclic Substrings | emt | WA | 55ms | 339428kb | C++20 | 3.5kb | 2024-08-02 19:24:23 | 2024-08-02 19:24:25 |
Judging History
answer
// #pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
using ld = long double;
using i128 = __int128_t;
using u128 = __uint128_t;
// #define int long long
#define mem(a, b) memset((a), (b), sizeof(a))
#define all(a) (a).begin(), (a).end()
#define inf 0x3f3f3f3f
#define lowbit(x) (-x) & x
#define debug cout<<"$"
#define ls u << 1
#define rs u << 1 | 1
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
using pii = pair<int,int>;
mt19937 rnd(time(0));
const int MOD = 998244353;
const ld eps = 1;
int qmi(int m, int k){int res = 1, t = m;while (k){if (k & 1) res = (res * t) % MOD;t = t * t % MOD;k >>= 1;}return res;}
const int N = 6e6 + 7;
const int P = 13331;
time_t now = time(0);
struct mana
{
char s[N*2];
int k = 0;
int d[N*2]; // 回文半径函数
void init(string t)
{
int n = t.size()-1;
s[0] = '$', s[++k] = '#';
for (int i = 1; i <= n; i++)
s[++k] = t[i], s[++k] = '#';
}
void get_d(){
d[1]=1;
for(int i=2,l,r=1;i<=k;i++){
if(i<=r)d[i]=min(d[r-i+l],r-i+1);
while(s[i-d[i]]==s[i+d[i]])d[i]++;
if(i+d[i]-1>r)l=i-d[i]+1,r=i+d[i]-1;
}
}
}man[2];
unordered_map<u_short,u_short> mb;
u64 h[N], p[N];
vector<unordered_map<u_short,int>> id(N);
u64 get(int l, int r)
{
return h[r] - h[l - 1] * p[r - l + 1];
}
void solve()
{
int n;
string s0;
cin>>n>>s0;
int t = n;
man[1].init(" "+s0);
s0 = " " + s0 + s0;
man[0].init(s0);
p[0] = 1;
for (int i = 1; i <= 2*n; i ++ )
{
h[i] = h[i - 1] * P + s0[i];
p[i] = p[i - 1] * P;
}
man[0].get_d();
man[1].get_d();
int cnt = 0, cnt1 = 0;
for(int q=0;q<2;q++)
for (int i = 2; i <= man[q].k; i++)
{
int len;
int l,r;
if(i&1)
{
len = min(t/2*2,man[q].d[i]-1);
l = i/2-(len/2-1);
r = i/2+(len/2-1)+1;
}
else
{
len = min(((t-1)/2*2+1),man[q].d[i]-1);
l = i/2-len/2;
r = i/2+len/2;
}
if(!len) continue;
auto z = get(l,r);
// debug<<i<<"\n";
// debug<<l<<" "<<r<<" "<<len<<" "<<q<<"\n";
id[len][z] += (q?-1:1);
while(!mb.count(z)&&l<=r)
{
l++,r--;
auto t = get(l,r);
mb[z] = t;
z = t;
cnt1++;
}
cnt ++;
}
cout<<cnt<<" "<<cnt1<<"\n";
// std::cout << "当前时间戳(毫秒): " << std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() << std::endl;
int ans = 0;
for(int i=n;i;i--)
{
for(auto [c,d]:id[i])
{
ans += 1ll*d*d%MOD*i%MOD;
ans %= MOD;
if(i>2) id[i-2][mb[c]] += d;
}
}
// while(ma.size())
// {
// auto [c,d] = *ma.begin();
// ma.erase(ma.begin());
// auto [len,hash] = c;
// ans += (-len)*d%MOD*d%MOD;
// ans %= MOD;
// if(-len>=2)
// ma[{len+2,mb[hash]}]+=d;
// }
cout<<ans<<"\n";
}
signed main()
{
freopen("test.in","r",stdin);
// freopen("test.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T = 1;
// cin>>T;
while(T--)
solve();
}
/*
6677667766776677
*/
详细
Test #1:
score: 0
Wrong Answer
time: 55ms
memory: 339428kb
input:
5 01010
output:
0 0 0
result:
wrong answer 1st numbers differ - expected: '39', found: '0'