Submission #632875

# Submission time Handle Problem Language Result Execution time Memory
632875 2022-08-21T05:42:10 Z racsosabe Savez (COCI15_savez) C++14
0 / 120
212 ms 16056 KB
#include<bits/stdc++.h>
using namespace::std;

const int B = 311;
const int MOD = 1e9 + 7;
const int N = 2000000 + 5;

int mul(int a, int b){
	return (1ll * a * b) % MOD;
}

int pow_mod(int a, int b){
	int r = 1;
	while(b){
		if(b & 1) r = mul(r, a);
		a = mul(a, a);
		b >>= 1;
	}
	return r;
}

int n;
char s[N];
int pot[N];
int poti[N];
int prefix[N];
map<int, int> best;

void init(){
	pot[0] = 1;
	for(int i = 1; i < N; i++) pot[i] = mul(pot[i - 1], B);
	poti[N - 1] = pow_mod(pot[N - 1], MOD - 2);
	for(int i = N - 2; i >= 0; i--) poti[i] = mul(poti[i + 1], B);
}

bool check(int l, int len){
	int L = prefix[l];
	int R = mul((prefix[len] + MOD - prefix[len - l]), poti[len - l]);
	return L == R;
}

int main(){
	init();
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		scanf("%s", s + 1);
		int len = strlen(s + 1);
		for(int j = 1; j <= len; j++) prefix[j] = (prefix[j - 1] + mul(pot[j], s[j])) % MOD;
		for(int l = 1; l <= len; l++){
			if(check(l, len)){
				int cur = 1 + (best.count(prefix[l]) ? best[prefix[l]] : 0);
				best[prefix[l]] = cur;
			}
		}
	}
	int ans = 0;
	for(auto e : best){
		if(ans < e.second) ans = e.second;
	}
	printf("%d\n", ans);
	return 0;
}

Compilation message

savez.cpp: In function 'int main()':
savez.cpp:44:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
savez.cpp:46:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |   scanf("%s", s + 1);
      |   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 26 ms 15956 KB Output is correct
2 Incorrect 29 ms 15888 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 15912 KB Output is correct
2 Correct 27 ms 15928 KB Output is correct
3 Incorrect 28 ms 15888 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 204 ms 15956 KB Output is correct
2 Incorrect 212 ms 16056 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 15948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 56 ms 15956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 51 ms 15956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 50 ms 15964 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 55 ms 15964 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 58 ms 15876 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 72 ms 15952 KB Output isn't correct
2 Halted 0 ms 0 KB -