# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
879736 | 2023-11-28T03:23:53 Z | Phuong0703 | Palindromic Partitions (CEOI17_palindromic) | C++14 | 167 ms | 28896 KB |
/* Cred : SunnyYeahBoi It's my last chance (⌐■_■) Problem : */ #include<bits/stdc++.h> using namespace std; #define int long long #define double long double #define all(v) v.begin(), v.end() #define endl "\n" #define NAME "a" const int MAXN = 1e6 + 5; const int inf = 1e18; const int MOD = 1e9 + 7; void FileInput(){ if(fopen(NAME".inp" , "r") == NULL) freopen(NAME".inp" , "w" , stdout); freopen(NAME".inp" , "r" , stdin); freopen(NAME".out" , "w" , stdout); } const int BASE = 311; string s; int pref[MAXN] , powBase[MAXN]; int get(int l , int r){ return ((pref[r] - (pref[l - 1] * powBase[r - l + 1]) % MOD) % MOD + MOD) % MOD; } void solve(){ cin >> s; int n = s.size(); s = '*' + s; powBase[0] = 1; for(int i = 1 ; i < MAXN ; i++) powBase[i] = powBase[i - 1] * BASE % MOD; for(int i = 1 ; i < s.size() ; i++) pref[i] = (pref[i - 1] * BASE + (s[i] - 'a' + 1)) % MOD; int curL = 1 , curR = n , res = 0; while(curL <= curR){ int len = 1; while(curL + len - 1 <= curR && get(curL , curL + len - 1) != get(curR - len + 1 , curR)){ // cout << curL << " " << curR << " " << len << " " << get(curL , curL + len - 1) << " " << get(curR - len + 1 , curR) << endl; len++; } if(curL + len - 1 < curR - len + 1) res += 2; else res++; curL += len; curR -= len; // cout << curL << " " << curR << endl; } cout << res << endl; } int32_t main(){ // FileInput(); ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int t = 1; cin >> t; while(t--) solve(); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 44 ms | 8792 KB | Output is correct |
2 | Correct | 44 ms | 8816 KB | Output is correct |
3 | Correct | 23 ms | 8792 KB | Output is correct |
4 | Correct | 44 ms | 8796 KB | Output is correct |
5 | Correct | 44 ms | 8796 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 44 ms | 8792 KB | Output is correct |
2 | Correct | 44 ms | 8816 KB | Output is correct |
3 | Correct | 23 ms | 8792 KB | Output is correct |
4 | Correct | 44 ms | 8796 KB | Output is correct |
5 | Correct | 44 ms | 8796 KB | Output is correct |
6 | Correct | 44 ms | 8840 KB | Output is correct |
7 | Correct | 27 ms | 8796 KB | Output is correct |
8 | Correct | 44 ms | 8796 KB | Output is correct |
9 | Correct | 44 ms | 8820 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 44 ms | 8792 KB | Output is correct |
2 | Correct | 44 ms | 8816 KB | Output is correct |
3 | Correct | 23 ms | 8792 KB | Output is correct |
4 | Correct | 44 ms | 8796 KB | Output is correct |
5 | Correct | 44 ms | 8796 KB | Output is correct |
6 | Correct | 44 ms | 8840 KB | Output is correct |
7 | Correct | 27 ms | 8796 KB | Output is correct |
8 | Correct | 44 ms | 8796 KB | Output is correct |
9 | Correct | 44 ms | 8820 KB | Output is correct |
10 | Correct | 45 ms | 8796 KB | Output is correct |
11 | Correct | 27 ms | 8796 KB | Output is correct |
12 | Correct | 46 ms | 8968 KB | Output is correct |
13 | Correct | 46 ms | 8796 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 44 ms | 8792 KB | Output is correct |
2 | Correct | 44 ms | 8816 KB | Output is correct |
3 | Correct | 23 ms | 8792 KB | Output is correct |
4 | Correct | 44 ms | 8796 KB | Output is correct |
5 | Correct | 44 ms | 8796 KB | Output is correct |
6 | Correct | 44 ms | 8840 KB | Output is correct |
7 | Correct | 27 ms | 8796 KB | Output is correct |
8 | Correct | 44 ms | 8796 KB | Output is correct |
9 | Correct | 44 ms | 8820 KB | Output is correct |
10 | Correct | 45 ms | 8796 KB | Output is correct |
11 | Correct | 27 ms | 8796 KB | Output is correct |
12 | Correct | 46 ms | 8968 KB | Output is correct |
13 | Correct | 46 ms | 8796 KB | Output is correct |
14 | Correct | 167 ms | 27648 KB | Output is correct |
15 | Correct | 95 ms | 22808 KB | Output is correct |
16 | Correct | 158 ms | 28896 KB | Output is correct |
17 | Correct | 107 ms | 18900 KB | Output is correct |