답안 #122927

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
122927 2019-06-29T14:47:36 Z davitmarg Palindromic Partitions (CEOI17_palindromic) C++17
100 / 100
58 ms 11156 KB
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <bitset>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iterator>
#include <ctype.h>
#include <stdlib.h>
#include <cassert>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(),v.end()
#define FIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;


int t;
string s;
LL h1,h2,p=351,a=1;

int main()
{
	FIO;
    cin>>t;
    while(t--)
	{
		cin>>s;
        int ans=0;
        for(int i=0;i<s.length();i++)
		{
            h1+=a*(s[i]-'a'+1);
            h2*=p;
            h2+=s[s.length()-1-i]-'a'+1;
            a*=p;
            if(h1==h2)
			{
				a=1;
                h1=h2=0;
                ans++;
			}
		}
		cout<<ans<<endl;
	}

	return 0;
}

/*

4 4 1
1 2
2 3




*/


Compilation message

palindromic.cpp: In function 'int main()':
palindromic.cpp:42:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<s.length();i++)
                     ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 252 KB Output is correct
4 Correct 2 ms 372 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 252 KB Output is correct
4 Correct 2 ms 372 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 252 KB Output is correct
4 Correct 2 ms 372 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 3 ms 504 KB Output is correct
13 Correct 2 ms 552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 252 KB Output is correct
4 Correct 2 ms 372 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 3 ms 504 KB Output is correct
13 Correct 2 ms 552 KB Output is correct
14 Correct 54 ms 11156 KB Output is correct
15 Correct 32 ms 6544 KB Output is correct
16 Correct 58 ms 10644 KB Output is correct
17 Correct 25 ms 6036 KB Output is correct