QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#708089 | #4384. Walk | hejinming983282# | RE | 0ms | 0kb | C++23 | 2.1kb | 2024-11-03 19:29:36 | 2024-11-03 19:29:39 |
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr)
#define _for(i,a,b) for(int i=(a) ;i<=(b) ;i++)
#define _rep(i,a,b) for(int i=(a) ;i>=(b) ;i--)
#define mst(v,s) memset(v,s,sizeof(v))
#define pii pair<int ,int >
#define pb(v) push_back(v)
#define all(v) v.begin(),v.end()
#define int long long
#define inf 0x3f3f3f3f
#define INF 0x7f7f7f7f7f7f7f7f
#define endl "\n"
#define fi first
#define se second
#define ls p<<1
#define rs p<<1|1
#define lson p<<1,l,mid
#define rson p<<1|1,mid+1,r
#define AC return 0
#define ldb long double
const int N=2e6+5;
const int mod=998244353;
const double eps=1e-8;
ll nxt[N];
void qnxt(char *c){
int len = strlen(c);
int p = 0, k = 1, l;
nxt[0] = len;
while(p + 1 < len && c[p] == c[p + 1]) p++;
nxt[1] = p;
for(int i = 2; i < len; i++){
p = k + nxt[k] - 1;
l = nxt[i - k];
if(i + l <= p) nxt[i] = l;
else{
int j = max(0ll, p - i + 1ll);
while(i + j < len && c[i + j] == c[j]) j++;
nxt[i] = j;
k = i;
}
}
}
int lb,tag[N];
char b[N];
ll ans;
signed main(){
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
IOS;
int T;cin>>T;
while( T-- ){
cin >> b;
int k;cin>>k;
qnxt(b);
lb = strlen(b);
//枚举以i开始的后缀,贡献差分
for(int i=0 ;i<lb ;i++){
int X = nxt[i];
int id = i+1;//真实下标
//找最左和最右的pre[1...i]算贡献
if( X>=id && X-id+1 >= k){
tag[2*(id-1) + k]++;//左
int t = (X-id+1)/k*k;
if( 2*(id-1) + t + k <= lb ) tag[2*(id-1) + t + k]--;
}
}
int ans=1;
_for(i,1,lb){
if( i-k>=1) tag[i] = tag[i] + tag[i-k];
ans = ans * (tag[i]+1)%mod;
}
cout<<ans<<endl;
_for(i,0,lb+k){
tag[i]=0;
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
99990 99987 757148 167851001 301413357 336971125 659598369 160567226 391749388 4890852 35766291 26239573 473038165 597007 3615545 326051437 392289611 118341523 170427799 37215529 675016434 168544291 683447134 950090227 82426873 116752252 194041605 706221269 71664782 257655784 84970744 21417563 37379...