Submission #955848

# Submission time Handle Problem Language Result Execution time Memory
955848 2024-03-31T15:26:09 Z vjudge1 Palindromic Partitions (CEOI17_palindromic) C++17
0 / 100
7 ms 8792 KB
#include<bits/stdc++.h>
#define INF 1e18
#define fi first
#define se second
#define FOR(i, k, n) for(int i = k; i <= n; i++)
#define FOR1(i, k, n) for(int i = k; i >= n; i--)
#define pb push_back
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define ll long long
#define vll vector<ll>
#define pll pair<ll, ll>
#define re return 0
#define input "AD.inp"
#define output "AD.out"
#define rf 	freopen(input, "r", stdin); freopen(output, "w", stdout)
using namespace std;
const int maxn = 1e6 + 5;
const int base = 57;
const int mod = 1e9 + 7;
ll Hash[maxn];
ll H[maxn];
int get_hash(int l, int r)
{
	if(l > r)
		return -1;
	return (Hash[r] - Hash[l - 1] * H[r - l + 1] + mod * mod) % mod;
}
int main()
{
	fastio;
	H[0] = 1;
	FOR(i, 1, 1000000)
		H[i] = (H[i - 1] * base) % mod;
	int t;
	cin >> t;
	while(t--)
	{
		string s;
		cin >> s;
		int n = s.size();
		Hash[0] = 0;
		s = ' ' + s;
		FOR(i, 1, n)
			Hash[i] = (Hash[i - 1] * base + s[i]) % mod;
		int l = 1, r = n, l1 = 1, r1 = n;
		int ans = 0;
		while(l1 < r1)
		{
			l1 = l, r1 = r;
			while(get_hash(l, l1) != get_hash(r1, r) && r1 > l1)
			{
				l1++;
				r1--;
			}
			if(l1 < r1)
			{
				ans += 2;
				l = l1 + 1;
				r = r1 - 1;
			}
			else
			{
				ans++;
				break;
			}
			if(l > r)
				break;
		}
		cout << ans << "\n";
	}
	re;
}

Compilation message

palindromic.cpp: In function 'int get_hash(int, int)':
palindromic.cpp:29:53: warning: integer overflow in expression of type 'int' results in '-371520463' [-Woverflow]
   29 |  return (Hash[r] - Hash[l - 1] * H[r - l + 1] + mod * mod) % mod;
      |                                                 ~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 8792 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 8792 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 8792 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 8792 KB Output isn't correct
2 Halted 0 ms 0 KB -