# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
240189 | 2020-06-18T13:47:02 Z | Nucleist | Palindromic Partitions (CEOI17_palindromic) | C++14 | 396 ms | 131072 KB |
#include <bits/stdc++.h> using namespace std; #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define debug(x) cerr << " - " << #x << ": " << x << endl; #define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl; #define all(x) (x).begin(),(x).end() #define sz(x) (ll)x.size() #define ll long long #define INF 1000000000 #define MOD 1000000007 #define pb push_back #define ve vector<ll> #define dos pair<ll,ll> #define vedos vector<dos> #define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) #define EPS 0.000001 struct greateri { template<class T> bool operator()(T const &a, T const &b) const { return a > b; } }; void setIO(string s) { ios_base::sync_with_stdio(0); cin.tie(0); freopen((s+".in").c_str(),"r",stdin); freopen((s+".out").c_str(),"w",stdout); } ve pi; ll mi=1e9+9; ve compute_hash(string const& s) { const ll p = 31; const ll m = 1e9 + 9; long long hash_value = 0; long long p_pow = 1; ve cur; for (char c : s) { hash_value = (hash_value + (c - 'a' + 1) * p_pow) % m; pi.pb(p_pow); p_pow = (p_pow * p) % m; cur.pb(hash_value); } return cur; } ve compute_hash1(string const& s) { const ll p = 31; const ll m = 1e9 + 9; long long hash_value = 0; long long p_pow = 1; ve cur; for (ll i = s.size()-1; i >= 0; --i) { char c=s[i]; hash_value = (hash_value*31)%m; hash_value = (hash_value + (c - 'a' + 1)) % m; p_pow = (p_pow * p) % m; cur.pb(hash_value); } return cur; } int main() { //freopen("tit.txt","r",stdin); //freopen("out","w",stdout); flash; ll nb; cin>>nb; ve now,now1; while(nb--){ string ka; cin>>ka; now=compute_hash(ka); now1=compute_hash1(ka); reverse(all(now1)); ll n=sz(ka); ll last=INF; ll last1=INF; ll ans=0; ll kobr=n; for (int i = 0; i < ka.size()/2; ++i) { ll cur=0,cur1=0; if(last!=INF){ cur=(now1[n-i-1]-((ll)((now1[n-last1-1]*pi[i-last1]))%mi)+mi)%mi; cur=(ll)((cur*pi[last1+1]))%mi; cur1=(now[i]-now[last]+mi)%mi; } else{ cur=(now1[n-i-1]); cur1=(now[i]); } if(cur==cur1){ if(last!=INF)kobr-=(i-last)*2; else kobr-=(i+1)*2; last=i; last1=i; ans+=2; } } if(kobr)ans++; cout<<ans<<'\n'; } return 0; } //code the AC sol ! // BS/queue/map
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 360 KB | Output is correct |
3 | Correct | 5 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 360 KB | Output is correct |
3 | Correct | 5 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
6 | Correct | 5 ms | 384 KB | Output is correct |
7 | Correct | 5 ms | 384 KB | Output is correct |
8 | Correct | 6 ms | 384 KB | Output is correct |
9 | Correct | 5 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 360 KB | Output is correct |
3 | Correct | 5 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
6 | Correct | 5 ms | 384 KB | Output is correct |
7 | Correct | 5 ms | 384 KB | Output is correct |
8 | Correct | 6 ms | 384 KB | Output is correct |
9 | Correct | 5 ms | 384 KB | Output is correct |
10 | Correct | 9 ms | 2040 KB | Output is correct |
11 | Correct | 8 ms | 1404 KB | Output is correct |
12 | Correct | 10 ms | 2040 KB | Output is correct |
13 | Correct | 9 ms | 1816 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 360 KB | Output is correct |
3 | Correct | 5 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
6 | Correct | 5 ms | 384 KB | Output is correct |
7 | Correct | 5 ms | 384 KB | Output is correct |
8 | Correct | 6 ms | 384 KB | Output is correct |
9 | Correct | 5 ms | 384 KB | Output is correct |
10 | Correct | 9 ms | 2040 KB | Output is correct |
11 | Correct | 8 ms | 1404 KB | Output is correct |
12 | Correct | 10 ms | 2040 KB | Output is correct |
13 | Correct | 9 ms | 1816 KB | Output is correct |
14 | Runtime error | 396 ms | 131072 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
15 | Halted | 0 ms | 0 KB | - |