Submission #1203192

#TimeUsernameProblemLanguageResultExecution timeMemory
1203192ender_shayanPalindromic Partitions (CEOI17_palindromic)C++20
15 / 100
10 ms23948 KiB
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef pair<int, int> pii ; typedef pair<ll, ll> pll ; typedef vector<pii> vii ; typedef vector<int> veci ; typedef vector<pll> vll ; typedef vector<ll> vecll; // find_by_order order_of_key //#pragma GCC optimize("O3,unroll-loops") //#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define F first #define S second #define pb push_back #define endl '\n' #define Mp make_pair #define all(x) x.begin(), x.end() #define debug(x) cerr << #x << " = " << x << endl #define set_dec(x) cout << fixed << setprecision(x); #define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define file_io freopen("in.txt" , "r" , stdin) ; freopen("out.txt" , "w" , stdout); #define lb lower_bound #define ub upper_bound #define for1(n) for(int i=1;i<=n;i++) #define for0(n) for(int i=0;i<n;i++) #define forn(n) for(int i=n;i>0;i--) #define pq priority_queue <pii, vector<pii>, greater<pii>> ll mod = 1e9+7; ll inf=1e18; const int N=1e6+100,L=21,bs=1000033,bs2=1000039; int A[N],B[N],C[N],D[N],E[N],n,m,k,q,dp[N],pre[N],dist[N],vis[N]; vector<int>g[N]; ll pw[N],pw2[N]; int main(){ fast_io int T;cin>>T; pw[0]=pw2[0]=1; for1(200)pw[i]=pw[i-1]*bs%mod; while(T--){ string s;cin>>s;s='0'+s; n=s.size()-1; int l=1,r=n,ans=0; ll h1=0,h2=0,h3=0,h4=0; while(l<=n/2){ h1=(h1+pw[s[l]])%mod; h2=(h2+pw[s[r]])%mod; h3=(h3+pw2[s[l]])%mod; h4=(h4+pw2[s[r]])%mod; if(h1==h2 && h3==h4) ans+=2; l++;r--; } ans+=(h1!=h2 || h3!=h4 || n%2==1); cout<<ans<<endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...