답안 #939132

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
939132 2024-03-06T06:07:55 Z Minbaev Palindromic Partitions (CEOI17_palindromic) C++17
0 / 100
6 ms 8028 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pii pair<int,int>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define f first
#define int long long
#define s second
#define pii pair<int,int>
template<class T>bool umax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>bool umin(T &a,T b){if(b<a){a=b;return true;}return false;}
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
	tree_order_statistics_node_update> ordered_set;
const int N = 1e6 + 5	;
const int inf = 1e17 + 7;
const int mod = 1e9 + 7;

int n,m,k;

vector<int>pw(N);

void solve(){
	
	
	string str;
	cin>>str;
	
	int l = 0,r = 0;
	int cnt1 = 0, cnt2 = 0;
	
	int i = 0,j = str.size() - 1;
	int ans = 0;
	
	while(i < j){
		
		l = (l + (str[i]-'a' + 1)*pw[cnt1]) % mod;
		r = (r * pw[cnt2]);
		r = r + (str[j]-'a'+1);
		r %= mod;
		i += 1;
		j -= 1;
		cnt1 += 1;
		cnt2 += 1;
		//~ cout<<l<<" "<<r<<"\n";
		if(l == r){
			ans += 2;
			l = 0;
			r = 0;
			cnt1 = 0;
			cnt2 = 0;
		}
		
	}
	
	if(l != 0 && r != 0 || i == j)ans += 1;
	
	cout<<ans<<"\n";
	
	
	
	
	
	
}

signed main()
{
	pw[0] = 1;
	for(int i = 1;i<N;i++){
		pw[i] = pw[i - 1]*31;
		pw[i] %= mod;
	}
	
//	freopen("seq.in", "r", stdin);
//  freopen("seq.out", "w", stdout);
	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int tt=1;cin>>tt;
	while(tt--)solve();

}

Compilation message

palindromic.cpp: In function 'void solve()':
palindromic.cpp:59:12: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   59 |  if(l != 0 && r != 0 || i == j)ans += 1;
      |     ~~~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 8028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 8028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 8028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 8028 KB Output isn't correct
2 Halted 0 ms 0 KB -