Submission #624770

# Submission time Handle Problem Language Result Execution time Memory
624770 2022-08-08T17:44:46 Z Alma Palindromic Partitions (CEOI17_palindromic) C++17
0 / 100
0 ms 212 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
using ll = long long;
using ii = pair<int,int>;

const int INF = 1e9;
const ll LLINF = 1e18;
using vi = vector<int>;
using vvi = vector<vi>;

void setIO (string fileName) {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    if (fileName != "std") {
        freopen((fileName + ".in").c_str(), "r", stdin);
        freopen((fileName + ".out").c_str(), "w", stdout);
    }
}

int main() {
    setIO("std");

    int tc;
	cin >> tc;


	while (tc--) {
		string s;
		cin >> s;
		int n = s.size();

		ll B = 239, M = 1e9+7;
		vector<ll> p(n), hs(n+1);
		p[0] = 1;
		
		for (int i = 0; i < n; i++) {
			if (i > 0) p[i] = (p[i-1] * B) % M;
			hs[i+1] = (hs[i] * B + s[i]) % M;
		}

		int l = 0, r = n, ans = 0;
		while (l < r) {
			int k = 1;
			while (hs[l+k] - (hs[l] * p[k]) % M != hs[r] - (hs[r-k] * p[k]) % M) {
				k++;
			}
			if (l+k == r) ans++;
			else ans += 2;
			l += k;
			r -= k;
		}

		cout << ans << '\n';
	}

    return 0;
}

Compilation message

palindromic.cpp: In function 'void setIO(std::string)':
palindromic.cpp:18:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen((fileName + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
palindromic.cpp:19:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen((fileName + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -