답안 #111486

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
111486 2019-05-15T13:05:07 Z dndhk Palindromic Partitions (CEOI17_palindromic) C++14
60 / 100
7038 ms 18416 KB
#include <bits/stdc++.h>

#define pb push_back
#define all(v) ((v).begin(), (v).end())
#define sortv(v) sort(all(v))
#define sz(v) ((int)(v).size())
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define umax(a, b) (a)=max((a), (b))
#define umin(a, b) (a)=min((a), (b))
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define rep(i,n) FOR(i,1,n)
#define rep0(i,n) FOR(i,0,(int)(n)-1)
#define FI first
#define SE second
#define INF 2000000000
#define INFLL 1000000000000000000LL


using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll P1 = 41;
const ll P2 = 43;
const ll DIV = 1000000009;

int T;
string str;

long long str1, str2;
vector<ll> vt1, vt2;

ll pw(ll x, ll y){
	if(y==0)	return 1;
	if(y==1)	return x;
	ll m = pw(x, y/2);
	if(y%2){
		return (((m*m)%DIV) * x) % DIV;
	}else{
		return (m*m) % DIV;
	}
}

bool fnd1(ll x){
	int s = 0, e = vt1.size()-1, m;
	while(s<e){
		m = (s+e)/2;
		if(vt1[m]<x)	s = m+1;
		else 	e = m;
	}
	return (vt1[s]==x);
}

bool fnd2(ll x){
	int s = 0, e = vt2.size()-1, m;
	while(s<e){
		m = (s+e)/2;
		if(vt2[m]<x)	s = m+1;
		else 	e = m;
	}
	return (vt2[s]==x);
}

int calc(){
	int x, y;
	x = 0; y = str.size()-1;
	int ans = 0;
	while(1){
		if(x>y)	return ans;
		if(x==y)	return ans+1;
		ll num1 = 0, num2 = 0;
		int l = 1;
		while(1){
			if(x+l-1 > y-l+1){
				return ans+1;
			}
			num1 = ((num1 * P1) + (ll)(str[x+l-1] - 'a' + 1)) % DIV;
			num2 = ((num2 * P2) + (ll)(str[x+l-1] - 'a' + 1)) % DIV;
			if(fnd1((str1 + num1 * pw(P1, x))%DIV) && fnd2((str2 + num2 * pw(P2, x))%DIV)){
				str1 = (str1 + num1 *  pw(P1, x))%DIV;
				str2 = (str2 + num2 *  pw(P2, x))%DIV;
				ans += 2;
				x = x+l; y = y-l;
				break;
			}
			l++;
		}
	}
}

int main(){
	cin>>T;
	while(T--){
		cin>>str;
		str1 = 0, str2 = 0;
		ll num1 = 0, num2 = 0;
		ll m1 = 1, m2 = 1;
		while(!vt1.empty())	vt1.pop_back();
		while(!vt2.empty())	vt2.pop_back();
		for(int i=str.size()-1; i>=0; i--){
			num1 = (num1 + (ll)(str[i]-'a'+1) * m1) % DIV;
			m1 = (m1 * P1) % DIV;
			vt1.pb(num1);
			num2 = (num2 + (ll)(str[i]-'a'+1) * m2) % DIV;
			m2 = (m2 * P2) % DIV;
			vt2.pb(num2);
		}
		sort(vt1.begin(), vt1.end());
		sort(vt2.begin(), vt2.end());
		printf("%d\n", calc());
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 128 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 128 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 128 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 33 ms 768 KB Output is correct
11 Correct 20 ms 664 KB Output is correct
12 Correct 27 ms 640 KB Output is correct
13 Correct 35 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 128 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 33 ms 768 KB Output is correct
11 Correct 20 ms 664 KB Output is correct
12 Correct 27 ms 640 KB Output is correct
13 Correct 35 ms 512 KB Output is correct
14 Incorrect 7038 ms 18416 KB Output isn't correct
15 Halted 0 ms 0 KB -