QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#236949#7512. Almost Prefix ConcatenationchroneZWA 2ms13976kbC++172.3kb2023-11-04 11:59:242023-11-04 11:59:24

Judging History

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

  • [2023-11-04 11:59:24]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:13976kb
  • [2023-11-04 11:59:24]
  • 提交

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;
string s, t; i64 S[N], T[N], pr[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;
		i64 B = T[y + M - 1] - (y == 0 ? 0 : T[y - 1]);
		i64 A = S[x + M - 1] - (x == 0 ? 0 : S[x - 1]);
		if(B * pr[x - y] == A) {
			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] * 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];
	}
	for(int i = 1; i < m; i++) {
		T[i] = T[i - 1] + val(t[i]) * pr[i];
	}

	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 
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

ababaab
aba

output:

473

result:

ok 1 number(s): "473"

Test #2:

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

input:

ac
ccpc

output:

5

result:

ok 1 number(s): "5"

Test #3:

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

input:

qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...

output:

75038697

result:

ok 1 number(s): "75038697"

Test #4:

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

input:

lvvvllvllvllvllllllllvvvllvlllvvlvlvllvlvvlvvvvlvvllllllvvlvlvvlllvvlvlvllllllvlvvvvvvlllvvvllvlvvvlvvlllvvvvvvlvlllvvvvlvvvvvlvvlvvlllvvllvvllvlvlvlvlvllllvvllvvllvlllvvvllllvvlvvllvvvvlvlvvlvvlllvvvvvvvvlvvlvlllvllvvvvllvvvlvvvvvvlvlllvllllvllllllllvvllllllvlvvlvvvlvllllvllvlvvllllllvlvvvlvlvlvvvl...

output:

538419149

result:

ok 1 number(s): "538419149"

Test #5:

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

input:

fzztyyyfztzzfzyztftyfzyyzzzztyyfzttzttztyzztyyyfyyftyfyfzzffyzffytttzttyzzftyfyfyftyyfzyzffyfyyzztzyyttyfyztfyfzyfzfzyftttfyyfyytzyyzfyyyzztfttzyyytzzffytyzyyyyfzfftftzzztyfftfzfzytftfttytfyzfytzfzztttttzzyztyftzzzfzfzfffttyztzfftfftyfyffztzyffttyyfyfzytytyyttfzzfyyytzzftzyyfftftyytyffzffztfytfyyyty...

output:

867833603

result:

ok 1 number(s): "867833603"

Test #6:

score: 0
Accepted
time: 1ms
memory: 13844kb

input:

xauxlgtqbsianlzjzglalnbtlujfrkfdqgczpmididmtamzeablrbrbjgtsdkzzcfhvcpdawqkrgdsereirlxbizhbsxlcbtgwwshekbhatqonvgupswcowythifpoubxkuoxuuisnzolzwektdcaouxbkhofvdqzmjulmhgqjxwzhgrzmorhqkgekntbzsxgvjtehfbterrhhjhqggzrqiqmcshzwpfoburpyfoehqgtitesyaekhlzcvxzdqmunyrlrhbrjoigdjzpcgptyoiowwnmqrxucxixxydurbdh...

output:

301464023

result:

ok 1 number(s): "301464023"

Test #7:

score: 0
Accepted
time: 1ms
memory: 13976kb

input:

tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt...

output:

816920406

result:

ok 1 number(s): "816920406"

Test #8:

score: -100
Wrong Answer
time: 1ms
memory: 13936kb

input:

cxccxccccxccxccxcxxxccxxcxcxcxcxxcccxcxccccccxccccxccxcxcxxcxxcxcxxxcxcccxcxxxxxccxxcccxxccxxxccxccxxxxcxxccccxccxxcccxcccxxxccccxcxcxccccxxxxccxxxxxcxxxxxxcxxccxxcxcxcxxxxxcxxccxcxxxcccxcxxxccccccccxxxcccxcxxcxxxxccxxxcccccxcccxccccccxxcccxxcccxxxccxxcxccxcccxxxccxccxxxccxcxxxxccxxcxcxxcxxccxxxcxcx...

output:

743092196

result:

wrong answer 1st numbers differ - expected: '206627037', found: '743092196'