Submission #939156

# Submission time Handle Problem Language Result Execution time Memory
939156 2024-03-06T06:20:09 Z vjudge1 Palindromic Partitions (CEOI17_palindromic) C++17
100 / 100
37 ms 11112 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 * 31);
		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;
      |     ~~~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 8284 KB Output is correct
2 Correct 6 ms 8284 KB Output is correct
3 Correct 6 ms 8284 KB Output is correct
4 Correct 6 ms 8284 KB Output is correct
5 Correct 6 ms 8284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 8284 KB Output is correct
2 Correct 6 ms 8284 KB Output is correct
3 Correct 6 ms 8284 KB Output is correct
4 Correct 6 ms 8284 KB Output is correct
5 Correct 6 ms 8284 KB Output is correct
6 Correct 7 ms 8284 KB Output is correct
7 Correct 6 ms 8284 KB Output is correct
8 Correct 6 ms 8284 KB Output is correct
9 Correct 7 ms 8284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 8284 KB Output is correct
2 Correct 6 ms 8284 KB Output is correct
3 Correct 6 ms 8284 KB Output is correct
4 Correct 6 ms 8284 KB Output is correct
5 Correct 6 ms 8284 KB Output is correct
6 Correct 7 ms 8284 KB Output is correct
7 Correct 6 ms 8284 KB Output is correct
8 Correct 6 ms 8284 KB Output is correct
9 Correct 7 ms 8284 KB Output is correct
10 Correct 7 ms 8284 KB Output is correct
11 Correct 6 ms 8284 KB Output is correct
12 Correct 6 ms 8284 KB Output is correct
13 Correct 6 ms 8284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 8284 KB Output is correct
2 Correct 6 ms 8284 KB Output is correct
3 Correct 6 ms 8284 KB Output is correct
4 Correct 6 ms 8284 KB Output is correct
5 Correct 6 ms 8284 KB Output is correct
6 Correct 7 ms 8284 KB Output is correct
7 Correct 6 ms 8284 KB Output is correct
8 Correct 6 ms 8284 KB Output is correct
9 Correct 7 ms 8284 KB Output is correct
10 Correct 7 ms 8284 KB Output is correct
11 Correct 6 ms 8284 KB Output is correct
12 Correct 6 ms 8284 KB Output is correct
13 Correct 6 ms 8284 KB Output is correct
14 Correct 36 ms 11112 KB Output is correct
15 Correct 23 ms 10836 KB Output is correct
16 Correct 37 ms 10964 KB Output is correct
17 Correct 22 ms 9792 KB Output is correct