QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#72926#4375. StringpoiAC ✓161ms15800kbC++1.7kb2023-01-20 13:29:012023-01-20 13:29:05

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-20 13:29:05]
  • 评测
  • 测评结果:AC
  • 用时:161ms
  • 内存:15800kb
  • [2023-01-20 13:29:01]
  • 提交

answer

#include "iostream"
#include "cstring"
#include "cstdio"
#include "algorithm"
#include "queue"
#include "vector"
#include "queue"
#include "stack"
#include "ctime"
#include "set"
#include "map"
using namespace std;
#define fi first
#define se second
#define vi vector<int>
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define mp make_pair
#define rep( i , a , b ) for( int i = (a) , i##end = b ; i <= i##end ; ++ i )
#define per( i , a , b ) for( int i = (a) , i##end = b ; i >= i##end ; -- i )
#define mem( a ) memset( a , 0 , sizeof (a) )
#define all( x ) x.begin() , x.end()
//#define int long long
typedef long long ll;
const int MAXN = 2e6 + 10;
const int P = 998244353;
int n , k;
char ch[MAXN];

int z[MAXN];
void init( char* s ) {
	int l = 0;
	rep( i , 1 , n - 1 ) {
		if( l + z[l] > i ) z[i] = min( z[i - l] , l + z[l] - i );
		while( i + z[i] < n && s[z[i]] == s[z[i] + i] ) ++ z[i];
		if( i + z[i] > l + z[l] ) l = i;
	}
	per( i , n , 1 ) z[i] = z[i - 1];
	z[1] = n;
}
int S[MAXN];
void solve() {
	scanf("%s",ch + 1);
	n = strlen( ch + 1 );
	scanf("%d",&k);
	init( ch + 1 );
//	rep( i , 1 , n ) printf("%d ",z[i]); puts("");
	rep( i , 1 , n ) if( z[i] ) {
		int se = z[i] - i + 1;
		if( se < k ) continue;
		int l = 2 * i - 1 + k - 1;
//		cout << l << ' ' << l + k * ( se / k ) << endl;
		++ S[l];
		-- S[l + k * ( se / k )];
	}
	int res = 1;
	rep( i , 1 , n ) {
		if( i >= k ) S[i] = ( S[i] + S[i - k] ) % P;
//		cout << S[i] << endl;
		res = ( res * 1ll * ( S[i] + 1 ) ) % P;
	}
	cout << res << endl;
	rep( i , 1 , n ) S[i] = z[i] = 0;
}

signed main() {
//	freopen("in","r",stdin);
//	freopen("out","w",stdout);
	int T;cin >> T;while( T-- ) solve();
//	solve();
}

详细

Test #1:

score: 100
Accepted
time: 161ms
memory: 15800kb

input:

10
kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk...

output:

811844748
106557744
583082277
750875845
539889742
198008691
286657978
344446711
612851418
36100066

result:

ok 10 lines