# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
279710 | 2020-08-22T10:03:56 Z | BeanZ | Palindromic Partitions (CEOI17_palindromic) | C++14 | 195 ms | 28552 KB |
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl '\n' const int N = 15; const int base = 311; const int mod = 1e9 + 7; ll h[1000006], p[1000006]; ll get(ll i, ll j){ return (h[j] - p[j - i + 1] * h[i - 1] + (ll)mod * mod) % mod; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); if (fopen("VietCT.INP", "r")){ freopen("VietCT.INP", "r", stdin); freopen("VietCT.OUT", "w", stdout); } ll t; cin >> t; while (t--){ string s; cin >> s; ll n = s.length(); if (n == 1){ cout << 1 << endl; continue; } s = " " + s; p[0] = 1; for (int i = 1; i <= n; i++){ p[i] = p[i - 1] * base % mod; } for (int i = 1; i <= n; i++){ h[i] = (h[i - 1] * base + (s[i] - 'a') + 1) % mod; } ll lb = 1, rb = 1, le = n, re = n; ll ans = 0; while (true){ if (get(lb, rb) == get(le, re)){ lb = rb + 1; re = le - 1; ans += 2; rb++; le--; if (rb > le){ cout << ans << endl; break; } if (rb == le){ cout << ans + 1 << endl; break; } } else { rb++; le--; if (rb >= le){ cout << ans + 1 << endl; break; } } } } } /* */
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 0 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 392 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 0 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 392 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Correct | 0 ms | 384 KB | Output is correct |
9 | Correct | 1 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 0 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 392 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Correct | 0 ms | 384 KB | Output is correct |
9 | Correct | 1 ms | 384 KB | Output is correct |
10 | Correct | 2 ms | 640 KB | Output is correct |
11 | Correct | 2 ms | 640 KB | Output is correct |
12 | Correct | 2 ms | 640 KB | Output is correct |
13 | Correct | 2 ms | 640 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 0 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 392 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Correct | 0 ms | 384 KB | Output is correct |
9 | Correct | 1 ms | 384 KB | Output is correct |
10 | Correct | 2 ms | 640 KB | Output is correct |
11 | Correct | 2 ms | 640 KB | Output is correct |
12 | Correct | 2 ms | 640 KB | Output is correct |
13 | Correct | 2 ms | 640 KB | Output is correct |
14 | Correct | 195 ms | 28552 KB | Output is correct |
15 | Correct | 107 ms | 23432 KB | Output is correct |
16 | Correct | 181 ms | 27732 KB | Output is correct |
17 | Correct | 109 ms | 15136 KB | Output is correct |