답안 #945254

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
945254 2024-03-13T15:17:23 Z Alkaser_ID Palindromic Partitions (CEOI17_palindromic) C++17
100 / 100
50 ms 12808 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;
                if (l == r - 1) --res;
            }
            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;
      |                      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 452 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 452 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 572 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 452 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 572 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 50 ms 12808 KB Output is correct
15 Correct 28 ms 7800 KB Output is correct
16 Correct 47 ms 11788 KB Output is correct
17 Correct 27 ms 7064 KB Output is correct