답안 #346112

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
346112 2021-01-09T06:28:45 Z ali_tavakoli Palindromic Partitions (CEOI17_palindromic) C++14
100 / 100
78 ms 19080 KB
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
#define pb push_back
#define F first
#define S second
//#pragma GCC optimize("Ofast")

const int maxn = 1e6 + 5, base = 29, md = 1e9 + 7;

int t, n;
ll pw[maxn];
string s;

void solve()
{
    cin >> s;
    ll h1 = 0, h2 = 0;
    int a = 0, b = s.size() - 1, p = 0, ans = 0;
    while(a < b)
    {
        h1 = ((h1 * base % md) + s[a ++]) % md;
        h2 = (h2 + pw[p ++] * s[b --] % md) % md;
        if(h1 == h2)
        {
            ans += 2;
            h1 = h2 = p = 0;
        }
    }
    if(h1 != h2|| a == b)
        ans ++;
    cout << ans << '\n';
}

int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    pw[0] = 1;
    for(int i = 1; i < maxn; i++)
        pw[i] = pw[i - 1] * base % md;
    cin >> t;
    while(t --)
        solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 8172 KB Output is correct
2 Correct 11 ms 8172 KB Output is correct
3 Correct 11 ms 8172 KB Output is correct
4 Correct 11 ms 8172 KB Output is correct
5 Correct 10 ms 8172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 8172 KB Output is correct
2 Correct 11 ms 8172 KB Output is correct
3 Correct 11 ms 8172 KB Output is correct
4 Correct 11 ms 8172 KB Output is correct
5 Correct 10 ms 8172 KB Output is correct
6 Correct 10 ms 8172 KB Output is correct
7 Correct 10 ms 8172 KB Output is correct
8 Correct 10 ms 8172 KB Output is correct
9 Correct 11 ms 8172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 8172 KB Output is correct
2 Correct 11 ms 8172 KB Output is correct
3 Correct 11 ms 8172 KB Output is correct
4 Correct 11 ms 8172 KB Output is correct
5 Correct 10 ms 8172 KB Output is correct
6 Correct 10 ms 8172 KB Output is correct
7 Correct 10 ms 8172 KB Output is correct
8 Correct 10 ms 8172 KB Output is correct
9 Correct 11 ms 8172 KB Output is correct
10 Correct 11 ms 8300 KB Output is correct
11 Correct 11 ms 8172 KB Output is correct
12 Correct 11 ms 8300 KB Output is correct
13 Correct 11 ms 8300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 8172 KB Output is correct
2 Correct 11 ms 8172 KB Output is correct
3 Correct 11 ms 8172 KB Output is correct
4 Correct 11 ms 8172 KB Output is correct
5 Correct 10 ms 8172 KB Output is correct
6 Correct 10 ms 8172 KB Output is correct
7 Correct 10 ms 8172 KB Output is correct
8 Correct 10 ms 8172 KB Output is correct
9 Correct 11 ms 8172 KB Output is correct
10 Correct 11 ms 8300 KB Output is correct
11 Correct 11 ms 8172 KB Output is correct
12 Correct 11 ms 8300 KB Output is correct
13 Correct 11 ms 8300 KB Output is correct
14 Correct 77 ms 19080 KB Output is correct
15 Correct 47 ms 14472 KB Output is correct
16 Correct 78 ms 18440 KB Output is correct
17 Correct 41 ms 13960 KB Output is correct