Submission #945251

# Submission time Handle Problem Language Result Execution time Memory
945251 2024-03-13T15:14:23 Z Alkaser_ID Palindromic Partitions (CEOI17_palindromic) C++17
0 / 100
0 ms 344 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
#include <iomanip>
//  cout << fixed << setprecision(9) <<  da;
const ll N = 5e5 + 10;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t; cin >> t;
    for (; t--;) {
        string s; cin >> s;
        ll n = s.length();
        ll res = 1;
        ll l = 0, r = n - 1;
        ll hl = 0, hr = 0, hl2 = 0, hr2 = 0;
        ll ph1 = 47, ph2 = 53;
        ll mod1 = 1e9 + 7, mod2 = 998244353;
        for (ll x = 47, y = 53; l < r;) {
            hl += (s[l] - 'a' + 1) * x; hl %= mod1;
            hr = (hr * 47) % mod1;
            hr += (s[r] - 'a' + 1) * 47;
            hl2 += (s[l] - 'a' + 1) * y; hl2 %= mod2;
            hr2 = (hr2 * 53) % mod2;
            hr2 += (s[r] - 'a' + 1) * 53;
            if (hl == hr && hl2 == hr2) {
                res += 2;
                hl = hr = hl2 = hr2 = 0;
                x = 47; y = 53;
            }
            else {
                x = (x * 47) % mod1;
                y = (y * 53) % mod2;
            }
            ++l; --r;
        }
        cout << res << '\n';
    }
}

Compilation message

palindromic.cpp: In function 'int main()':
palindromic.cpp:22:12: warning: unused variable 'ph1' [-Wunused-variable]
   22 |         ll ph1 = 47, ph2 = 53;
      |            ^~~
palindromic.cpp:22:22: warning: unused variable 'ph2' [-Wunused-variable]
   22 |         ll ph1 = 47, ph2 = 53;
      |                      ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -