QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#278883#4375. StringchunzhifengAC ✓438ms181052kbC++14918b2023-12-07 21:55:182023-12-07 21:55:18

Judging History

你现在查看的是最新测评结果

  • [2023-12-07 21:55:18]
  • 评测
  • 测评结果:AC
  • 用时:438ms
  • 内存:181052kb
  • [2023-12-07 21:55:18]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned ll
#define endl "\n"
#define PII pair<int,int>
const ll INF=0x3f3f3f3f;//3f3f3f3f;
const int mod=998244353;
const int N=1e6+5;
vector<int>g[N];
vector<int>cnt[N];
int ne[N],ans[N],k;
void dfs(int u){
	cnt[2*u%k].push_back(2*u);
	ans[u]=cnt[u%k].end()-upper_bound(cnt[u%k].begin(),cnt[u%k].end(),u);
	for(int &v:g[u]) dfs(v);
	cnt[2*u%k].pop_back();
}
void solve(){
	string s; cin>>s;
	int n=s.size(); s=" "+s;
	for(int i=0;i<=n;i++) g[i].clear();
	cin>>k;
	for(int i=2,j=0;i<=n;i++){
		while(j&&s[j+1]!=s[i]) j=ne[j];
		if(s[j+1]==s[i]) j++;
		ne[i]=j;
		g[ne[i]].push_back(i);
	} g[0].push_back(1);
	dfs(0);
	ll res=1;
	for(int i=1;i<=n;i++) res=res*(ans[i]+1)%mod;
	cout<<res<<endl;
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int T=1; cin>>T;
    while(T--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 438ms
memory: 181052kb

input:

10
kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk...

output:

811844748
106557744
583082277
750875845
539889742
198008691
286657978
344446711
612851418
36100066

result:

ok 10 lines