QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#193409#7512. Almost Prefix Concatenationucup-team191#WA 3ms24372kbC++143.4kb2023-09-30 17:06:262023-09-30 17:06:26

Judging History

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

  • [2023-09-30 17:06:26]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:24372kb
  • [2023-09-30 17:06:26]
  • 提交

answer

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iostream>
#include <map>
#include <set>
#include <ext/pb_ds/assoc_container.hpp>

#define X first
#define Y second
#define PB push_back

using namespace std;
using namespace __gnu_pbds;
//gp_hash_table, cc_hash_table, ordered_set

typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef pair < int, int > pii;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < ll, ll > pll;
typedef pair < pii, int > ppi;
typedef pair < int, pii > pip;
typedef long double ld;
typedef vector < int > vi;
typedef vector < ll > vl;

const int N = 1e6 + 500;
const int M = 1e6 + 500;
const int OFF = (1 << 18);
const int ALP = 30;
const int INF = 0x3f3f3f3f;
const int MOD = 998244353; // 1e9 + 7
const int BS = 31337;

inline int add(int A, int B) { if(A + B >= MOD) return A + B - MOD; return A + B; }
inline int sub(int A, int B) { if(A - B < 0) return A - B + MOD; return A - B; }
inline int mul(int A, int B) { return (ll)A * B % MOD; }

inline int pot(int A, int B){
	int ret = 1, bs = A;
	for(; B ; B >>= 1){
		if(B & 1) ret = mul(ret, bs);
		bs = mul(bs, bs);
	}
	return ret;
}

char s[N], t[N];
int hsh_s[N], hsh_t[N], bs[N];
int n, m, kol[N];

void calc_hash(){
	bs[0] = 1;
	for(int i = 1;i < N;i++)
		bs[i] = mul(bs[i - 1], BS);
	for(int i = 0;i < n;i++) {
		hsh_s[i] = mul(s[i], bs[i]);
		if(i) hsh_s[i] = add(hsh_s[i - 1], hsh_s[i]);
	}
	for(int i = 0;i < m;i++) {
		hsh_t[i] = mul(t[i], bs[i]);
		if(i) hsh_t[i] = add(hsh_t[i - 1], hsh_t[i]);
	}
}

inline bool eq(int l_s, int r_s, int l_t, int r_t) {
	if(r_t - l_t != l_s - r_s) return false;
	if(r_s < l_s) return true;
	if(s[l_s] != t[l_t]) return false;
	if(s[r_s] != t[r_t]) return false;
	int s_hsh = sub(hsh_s[r_s], l_s ? hsh_s[l_s - 1] : 0);
	int t_hsh = sub(hsh_t[r_t], l_t ? hsh_t[l_t - 1] : 0);
	return mul(s_hsh, bs[N - r_s - 10]) == mul(t_hsh, bs[N - r_t - 10]);
}

int dp_0[N], dp_1[N], dp_2[N];
int sm_0[N], sm_1[N], sm_2[N];

void solve(){
	scanf("%s", s);
	scanf("%s", t);
	n = strlen(s); m = strlen(t);
	calc_hash();
	for(int i = 0;i < n;i++) {
		int zaj = 0;
		for(int j = 19;j >= 0;j--) {
			if(zaj + (1 << j) <= m && zaj + (1 << j) + i <= n) {
				if(eq(i + zaj, i + zaj + (1 << j) - 1, zaj, zaj + (1 << j) - 1))
					zaj += (1 << j);
			}
		}
		if(zaj < m) zaj++;
		for(int j = 19;j >= 0;j--) {
			if(zaj + (1 << j) <= m && zaj + (1 << j) + i <= n) {
				if(eq(i + zaj, i + zaj + (1 << j) - 1, zaj, zaj + (1 << j) - 1))
					zaj += (1 << j);
			}
		}
		kol[i] = i + zaj;
	}
	dp_0[n] = 1; sm_0[n] = 1; 
	for(int i = n - 1;i >= 0;i--) {
		dp_0[i] = sub(sm_0[i + 1], sm_0[kol[i] + 1]);
		sm_0[i] = add(sm_0[i + 1], dp_0[i]);
	} 
	
	for(int i = n - 1;i >= 0;i--) {
		dp_1[i] = sub(sm_1[i + 1], sm_1[kol[i] + 1]);
		dp_1[i] = add(dp_1[i], dp_0[i]);
		sm_1[i] = add(sm_1[i + 1], dp_1[i]);
	}
	
	for(int i = n - 1;i >= 0;i--) {
		dp_2[i] = sub(sm_2[i + 1], sm_2[kol[i] + 1]);
		dp_2[i] = add(dp_2[i], mul(2, dp_1[i]));
		dp_2[i] = sub(dp_2[i], dp_0[i]);
		sm_2[i] = add(sm_2[i + 1], dp_2[i]);
	}
	
	printf("%d\n", dp_2[0]);
}

int main(){
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);
    int T = 1; 
    //scanf("%d", &T);
    for(;T--;) solve();
	return 0;
}






Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

ababaab
aba

output:

473

result:

ok 1 number(s): "473"

Test #2:

score: 0
Accepted
time: 3ms
memory: 24288kb

input:

ac
ccpc

output:

5

result:

ok 1 number(s): "5"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 24372kb

input:

qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...

output:

158904601

result:

wrong answer 1st numbers differ - expected: '75038697', found: '158904601'