QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#236994#7512. Almost Prefix ConcatenationchroneZWA 295ms79696kbC++172.8kb2023-11-04 12:19:342023-11-04 12:19:35

Judging History

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

  • [2023-11-04 12:19:35]
  • 评测
  • 测评结果:WA
  • 用时:295ms
  • 内存:79696kb
  • [2023-11-04 12:19:34]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using i64 = unsigned long long;

inline int val(char ch) {return ch - 'a' + 1;}

constexpr int N = 1e6 + 10;
int r[N];
int f[N], g[N], w[N], sf[N], sg[N], sw[N];

static constexpr int mod = 998244353;
inline int add(int x, int y) {return (x + y >= mod ? x + y - mod : x + y);}
inline int dec(int x, int y) {return (x - y < 0 ? x - y + mod : x - y);}
inline void ad(int &x, int y) {x = add(x, y);}
inline void de(int &x, int y) {x = dec(x, y);}

constexpr i64 P = 1004535809, P2 = 127;
string s, t; i64 S[N], T[N], S2[N], T2[N], pr[N], pr2[N]; int n, m;

inline int lcp(int x, int y) {
	assert(x >= y);
	int l = 0, r = min(n - x + 1, m - y + 1), res = 0;
	while(l <= r) {
		int M = l + r >> 1; int f = 1;
		i64 B = mod + T[y + M - 1] - (y == 0 ? 0 : T[y - 1]); B %= mod;
		i64 A = mod + S[x + M - 1] - (x == 0 ? 0 : S[x - 1]); A %= mod;
		f &= B * pr[x - y] % mod == A;
		
		B = P + T2[y + M - 1] - (y == 0 ? 0 : T2[y - 1]); B %= P;
		A = P + S2[x + M - 1] - (x == 0 ? 0 : S2[x - 1]); A %= P;
		f &= B * pr2[x - y] % P == A;
		if(f) {
			res = M;
			l = M + 1;
		} else {
			r = M - 1;
		}
	}
	return res;
}

int main() {
	ios::sync_with_stdio(false); 
	cin.tie(nullptr); cout.tie(nullptr);
	
	cin >> s >> t; n = s.size(), m = t.size();
	pr[0] = 1;
	for(int i = 1; i <= n; i++) {
		pr[i] = pr[i - 1] * P2 % mod;
		pr2[i] = pr2[i - 1] * P2 % P;
	}
	S[0] = val(s[0]), T[0] = val(t[0]);
	for(int i = 1; i < n; i++) {
		S[i] = S[i - 1] + val(s[i]) * pr[i];
		S[i] %= mod;
		S2[i] = S2[i - 1] + val(s[i]) * pr2[i];
		S2[i] %= P;
	}
	for(int i = 1; i < m; i++) {
		T[i] = T[i - 1] + val(t[i]) * pr[i];
		T[i] %= mod;
		T2[i] = T2[i - 1] + val(t[i]) * pr2[i];
		T2[i] %= P;
	}

	for(int i = 0; i < n; i++) {
		int L = lcp(i, 0);
		r[i] = i + L - 1;
		if(r[i] == n - 1) {
			continue;
		}
		if(r[i] == n - 2) {
			r[i] = n - 1;
			continue;
		}
		r[i] = r[i] + 2 + lcp(r[i] + 2, L + 1) - 1;
	}
	for(int i = 0; i < n; i++) {
		r[i] = min(r[i], i + m - 1);
	}
	// for(int i = 0; i < n; i++) {
	// 	int dif = 0;
	// 	for(int j = i; j < n && j - i < t.size(); j++) {
	// 		dif += (s[j] != t[j - i]);
	// 		if(dif >= 2) {
	// 			break;
	// 		}
	// 		r[i] = j;
	// 	}
	// }
	w[n] = 1; sw[n] = 1;
	for(int i = n - 1; i >= 0; i--) {
		ad(f[i], dec(sf[i + 1], sf[r[i] + 2]));
		ad(f[i], 2ll * dec(sg[i + 1], sg[r[i] + 2]) % mod);
		ad(f[i], dec(sw[i + 1], sw[r[i] + 2]));

		ad(g[i], dec(sg[i + 1], sg[r[i] + 2]));
		ad(g[i], dec(sw[i + 1], sw[r[i] + 2]));

		ad(w[i], dec(sw[i + 1], sw[r[i] + 2]));

		sf[i] = add(sf[i + 1], f[i]);
		sg[i] = add(sg[i + 1], g[i]);
		sw[i] = add(sw[i + 1], w[i]);
	}
	cout << f[0] << "\n";
}
/*
Author: chroneZ
Start thinking at 
Start coding at 
Finish debugging at 
*/

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 15936kb

input:

ababaab
aba

output:

473

result:

ok 1 number(s): "473"

Test #2:

score: 0
Accepted
time: 0ms
memory: 15992kb

input:

ac
ccpc

output:

5

result:

ok 1 number(s): "5"

Test #3:

score: 0
Accepted
time: 2ms
memory: 15916kb

input:

qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...

output:

75038697

result:

ok 1 number(s): "75038697"

Test #4:

score: 0
Accepted
time: 2ms
memory: 15884kb

input:

lvvvllvllvllvllllllllvvvllvlllvvlvlvllvlvvlvvvvlvvllllllvvlvlvvlllvvlvlvllllllvlvvvvvvlllvvvllvlvvvlvvlllvvvvvvlvlllvvvvlvvvvvlvvlvvlllvvllvvllvlvlvlvlvllllvvllvvllvlllvvvllllvvlvvllvvvvlvlvvlvvlllvvvvvvvvlvvlvlllvllvvvvllvvvlvvvvvvlvlllvllllvllllllllvvllllllvlvvlvvvlvllllvllvlvvllllllvlvvvlvlvlvvvl...

output:

538419149

result:

ok 1 number(s): "538419149"

Test #5:

score: 0
Accepted
time: 0ms
memory: 15884kb

input:

fzztyyyfztzzfzyztftyfzyyzzzztyyfzttzttztyzztyyyfyyftyfyfzzffyzffytttzttyzzftyfyfyftyyfzyzffyfyyzztzyyttyfyztfyfzyfzfzyftttfyyfyytzyyzfyyyzztfttzyyytzzffytyzyyyyfzfftftzzztyfftfzfzytftfttytfyzfytzfzztttttzzyztyftzzzfzfzfffttyztzfftfftyfyffztzyffttyyfyfzytytyyttfzzfyyytzzftzyyfftftyytyffzffztfytfyyyty...

output:

867833603

result:

ok 1 number(s): "867833603"

Test #6:

score: 0
Accepted
time: 2ms
memory: 15964kb

input:

xauxlgtqbsianlzjzglalnbtlujfrkfdqgczpmididmtamzeablrbrbjgtsdkzzcfhvcpdawqkrgdsereirlxbizhbsxlcbtgwwshekbhatqonvgupswcowythifpoubxkuoxuuisnzolzwektdcaouxbkhofvdqzmjulmhgqjxwzhgrzmorhqkgekntbzsxgvjtehfbterrhhjhqggzrqiqmcshzwpfoburpyfoehqgtitesyaekhlzcvxzdqmunyrlrhbrjoigdjzpcgptyoiowwnmqrxucxixxydurbdh...

output:

301464023

result:

ok 1 number(s): "301464023"

Test #7:

score: 0
Accepted
time: 2ms
memory: 16076kb

input:

tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt...

output:

816920406

result:

ok 1 number(s): "816920406"

Test #8:

score: 0
Accepted
time: 0ms
memory: 18200kb

input:

cxccxccccxccxccxcxxxccxxcxcxcxcxxcccxcxccccccxccccxccxcxcxxcxxcxcxxxcxcccxcxxxxxccxxcccxxccxxxccxccxxxxcxxccccxccxxcccxcccxxxccccxcxcxccccxxxxccxxxxxcxxxxxxcxxccxxcxcxcxxxxxcxxccxcxxxcccxcxxxccccccccxxxcccxcxxcxxxxccxxxcccccxcccxccccccxxcccxxcccxxxccxxcxccxcccxxxccxccxxxccxcxxxxccxxcxcxxcxxccxxxcxcx...

output:

206627037

result:

ok 1 number(s): "206627037"

Test #9:

score: 0
Accepted
time: 0ms
memory: 16100kb

input:

vmqvvbbmvmmmqqvqvmmbbvqbqvbmmbqmvvbmmmqvqvbvqqmvbbmmvmvqbvmqqbqvqqvmvmmbqvvbvmvbqmqqbqqqbqqmvvmmbvvvbvvvbmqqvbqbmvvmvqqvbqbvvvqmvvvmvqqmvqbmbvmvmqmmbmqqqbbmvqbqbbqqbmmvmmqqqvvvqqqqqmmvvvvqmvmmmmvmqmqbbvbvvqmmmqbbmvqvmvmqbqbbbmqbqbqmqbqmqbmvvqmmvbmmbvbqqvmmmbbmbbmvmmvbmqmqbbqqbqqbbqmbmmmqbqbmvbmvmmmm...

output:

460659355

result:

ok 1 number(s): "460659355"

Test #10:

score: 0
Accepted
time: 0ms
memory: 16092kb

input:

xthikaxiescbqjzrpgtcpigqjsojlsxsiowkkzsdsgscoolhdtglvpgcoggzqnnjmocvanrogbzqjcmijoukjicadaakehxgjphjgnskjvfneoyaucfadilscsucjgweuzcdfapfnrfffdowxvzkvgqzmtszjldylvehzjlvmhproaehqhuwdoadenqdrqwrlxxfouzqolwbopmkpjshczocnnsxktxozahzwqpwbmvexguvjhbvbjwsdtgaitoqwsfzkwnzgeidkamgcfhzhitfxenunlcsbsesbczvmmbu...

output:

906223232

result:

ok 1 number(s): "906223232"

Test #11:

score: 0
Accepted
time: 11ms
memory: 27428kb

input:

bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...

output:

39285513

result:

ok 1 number(s): "39285513"

Test #12:

score: 0
Accepted
time: 27ms
memory: 27352kb

input:

hghggghghhghhgghgggghhghhhgghggghghhhhghghgggghhggggghhgghggghhhghggghghghggghggghgghhhghgggghghghgggghhhhhgghhgghhhghhghhhghhhhhhghghhgggggghghgggghghhghhgghhghhhhhhghgghhghghgggghgggggghghhhhhghhhhhhhgghhggggghhgghhhhhhhhghggggggghhghhghhghhgghhghgghhhhgghghghhhhhghggghhhhhhhgggggghgghghhhhghhgggg...

output:

58618935

result:

ok 1 number(s): "58618935"

Test #13:

score: 0
Accepted
time: 24ms
memory: 25904kb

input:

nnttcybbmnrnsuybrkmkmtumcyuyrrmbtybutunsyrkmunmncmkuknttmmtkymtcybttrmyrtckscttcksbtymtyukbbynnnbukttncmbutscbrytbrutnuyuknmtymckkttrrnsbtrkbnnnkbrccrcyybmnnybbkkbcbbccycsrcytnuucbbyytckrycktsmkymruycksrscytkskscbtbccbrurmumrkbkbttkcynmymbbmbkrksmnusryumsmmyrcsmusumbrkkbmsbyytmmruubskccsusnntcuntrrt...

output:

46252951

result:

ok 1 number(s): "46252951"

Test #14:

score: 0
Accepted
time: 24ms
memory: 28156kb

input:

ittaztseqcdirziayobnnxuzipvteycmgjbupnlxuheulnmzsdeymctprlxvkvzjwrotsauxagyrqcwzuwqyodrqsupwpyrmbwjqlvfdsrocneigxvnjfiseotxmutzwacfutqlmzmxwuqgjugwkafnxvzutgbrweqrdshwneksgxzzinnmbbioqdvbmavukaegvkpwauuoysklelsqhytlikpdpymbwhmbdmrycaiywtwjjqtecwoofyjhbumjtipwyopkuralejvopitpjcdswcvsugimgbrlibrteaqtb...

output:

838361918

result:

ok 1 number(s): "838361918"

Test #15:

score: 0
Accepted
time: 160ms
memory: 79188kb

input:

llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll...

output:

774442405

result:

ok 1 number(s): "774442405"

Test #16:

score: 0
Accepted
time: 270ms
memory: 78284kb

input:

nnnddndnndnddddndnnddnddnndddndndnnndnndndndnnnddndndnddnnddnndndndnnnndndddndnndndnndddndnnddnndndnnddnnddnddndddnnnndnnndddnndnddnnnddndddnndnnndndndndnddnddnndddndddnnndddnnndnndnndnnnddnnddnndnnndnnnddnnddddnndnnddnndnnnddddnddnnndnnddddddndndnnnnndnnnndddddnddnnndddndnnddndnnnddddnndndnndndndnd...

output:

478212008

result:

ok 1 number(s): "478212008"

Test #17:

score: 0
Accepted
time: 281ms
memory: 79696kb

input:

ievnetxypatirsocqrmgmhfxnkgzrscclietylohbcshjjxfmqhlxvebythkwllhjxwjngxbjeivttdgjttmyqgxsqotxueuvzrslcqpranaucprjmfczshtoqggczmbuwixllhnlcjhrvfixisvqdlxxmevucbvzolweshgvxeocppggthqkljyiszeqkpnybogisosqzdasfqgpuzudnnabwoqtrpxllqkxlbwsexwduvutufncthrmywlsqlccetggdflmgewzvhsmpyznzsxcftkoyfhgmgvliwxbywi...

output:

702291108

result:

ok 1 number(s): "702291108"

Test #18:

score: 0
Accepted
time: 150ms
memory: 79500kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

301945039

result:

ok 1 number(s): "301945039"

Test #19:

score: 0
Accepted
time: 295ms
memory: 79448kb

input:

gggggcgcgggcgccgggcgcccgccccggcccgcggccccggcccccggccgccccccggcccgggcccgggggcccgggggcgggccgcccccccgcgcggggggggggcggggggcggccgcccggggccgccccgcgcgggcggggccgcgcggcggccgggccgccgcggcccgcccggcgccgccgggcgggggcggggccgccgcccccgccccccgggggcgcgcgccggccggcggcggggcgccggcgccccggccgggggccgccccccccgcggcgcggggggcgccc...

output:

602912498

result:

ok 1 number(s): "602912498"

Test #20:

score: -100
Wrong Answer
time: 276ms
memory: 79448kb

input:

zdomsivxdzqlpexdauxxrjvembwqtchcxcpboqwmilagfpnrzyicztptfvdlqehajqoxcqvtoglsusgfioxtwheivlmgapepuoevghzmdadbkkkrdusnvxmansofunrgmppyktkxcottuiolirqlsflpnkghhxngutoovfzluiboooswqknpedyiaspikpveswjqnqitfbynjgiqymkrldekgmkavalduxlscjewmpoctbxjujtxlavpibkyerspcfchiticgjsvmzvtadhimnvacljbhmzikeabhjoszfig...

output:

449934048

result:

wrong answer 1st numbers differ - expected: '435002470', found: '449934048'