답안 #939153

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
939153 2024-03-06T06:18:07 Z vjudge1 Palindromic Partitions (CEOI17_palindromic) C++17
100 / 100
226 ms 7932 KB
///*                                                    __                    __                        __                    */
///*        ======     _      /| /|  __   _            /   |  |   /|  |   @  |    |  |  | /   /| |\  | /   |  |  @ | /        */
///* \-       ||  |_| |_     / |/ | |  | |_  |-        |   |--|  /-|  |   |  \ \  |==|  |-   /=| | \ | |   |--|  | |-         */
///*          ||  | | |_    /     | |__|  _| |_        \__ |  | /  |  |__ |  __|  |  |  | \ /  | |  \| \__ |  |  | | \        */
///* 
 
#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();
	}
}
 
 
 
 
 
 
 
 
 
 
 
 
 

Compilation message

palindromic.cpp:57:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   57 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 600 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 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 600 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 2 ms 348 KB Output is correct
11 Correct 2 ms 472 KB Output is correct
12 Correct 2 ms 348 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 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 600 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 2 ms 348 KB Output is correct
11 Correct 2 ms 472 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 222 ms 6484 KB Output is correct
15 Correct 219 ms 5608 KB Output is correct
16 Correct 226 ms 7932 KB Output is correct
17 Correct 32 ms 4732 KB Output is correct