제출 #939153

#제출 시각아이디문제언어결과실행 시간메모리
939153vjudge1Palindromic Partitions (CEOI17_palindromic)C++17
100 / 100
226 ms7932 KiB

///*                                                    __                    __                        __                    */
///*        ======     _      /| /|  __   _            /   |  |   /|  |   @  |    |  |  | /   /| |\  | /   |  |  @ | /        */
///* \-       ||  |_| |_     / |/ | |  | |_  |-        |   |--|  /-|  |   |  \ \  |==|  |-   /=| | \ | |   |--|  | |-         */
///*          ||  | | |_    /     | |__|  _| |_        \__ |  | /  |  |__ |  __|  |  |  | \ /  | |  \| \__ |  |  | | \        */
///* 
 
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define int long long
typedef vector<int> vi;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef vector<pii> vii;
const int N = 3e5+50, inf = 1e18, mod = 1e9+7;
int bp(int a, int n){
	if(n == 0)return 1;
	int b = bp(a, n >> 1)%mod;
	if(n&1)return b*b%mod*a%mod%mod;
	return b*b%mod%mod;
}
void solve(){
	int a = 0, b = 0;
	string s;
	cin >> s;
	int n = s.size(), ans = 0;
	
	int l = 0, r = n-1, sz = 0, p = 31;
	while(true){
		a += ((s[l]-'a'+1)*bp(p,(sz++)))%mod;
		b = b*p%mod + (s[r]-'a'+1);
		a %= mod;
		b %= mod;
		//cout << a << ' ' << b << '\n';
		if(a == b){
			if(l >= r){
				ans++;
				break;
			}else ans+=2;
			a = 0;
			sz = 0;
			b = 0;
		}
		l++;
		r--; 
		if(a == 0 && b == 0 && l > r)break;
		if(l > r){
			ans += 1;
			break;
		}
	}
	cout << ans << '\n';
}
main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int test = 1;
	cin >> test;
	while(test--){
		solve();
	}
}
 
 
 
 
 
 
 
 
 
 
 
 
 

컴파일 시 표준 에러 (stderr) 메시지

palindromic.cpp:57:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   57 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...