QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#56365#4375. StringqinjianbinAC ✓748ms179928kbC++171.1kb2022-10-18 23:09:502022-10-18 23:09:51

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-18 23:09:51]
  • 评测
  • 测评结果:AC
  • 用时:748ms
  • 内存:179928kb
  • [2022-10-18 23:09:50]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define _for(i, a, b) for(int i = (a); i <= (b); i++)
using namespace std;

typedef long long ll;
const int mod = 998244353;
const int N = 1e6 + 10;
vector<int> g[N], node[N];
int ans[N], n;

void AddEdge(int u, int v) {
	g[u].push_back(v);
}

char str[N];
int k;
int nxt[N];
void GetNxt() {
	int i = 0, j = -1, len = strlen(str);
	nxt[0] = -1;
	while (i < len) {
		if (j == -1 || str[i] == str[j]) {nxt[++i] = ++j; AddEdge(j, i);}
		else j = nxt[j];
	}
}

void dfs(int u)
{
	node[2 * u % k].push_back(2 * u);
	int pos = upper_bound(node[u % k].begin(), node[u % k].end(), u) - node[u % k].begin();
	ans[u] = node[u % k].size() - pos;
	for(int v: g[u]) dfs(v);
	node[2 * u % k].pop_back();
}

int main()
{
	int T; scanf("%d", &T);
	while(T--)
	{
		scanf("%s", str);
		scanf("%d", &k);
		n = strlen(str);
		_for(i, 0, n) g[i].clear();
		GetNxt();
		
		dfs(0);

		ll res = 1;
		_for(i, 1, n)
		{
			ll cur = ans[i] + 1;
			res = res * cur % mod;
		}
		printf("%lld\n", res);
	}

	return 0; 
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 748ms
memory: 179928kb

input:

10
kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk...

output:

811844748
106557744
583082277
750875845
539889742
198008691
286657978
344446711
612851418
36100066

result:

ok 10 lines