# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
628572 | 2022-08-13T13:46:49 Z | a_aguilo | Palindromic Partitions (CEOI17_palindromic) | C++14 | 440 ms | 26772 KB |
#include<bits/stdc++.h> using namespace std; const int p = 31; const long long m = 1e9 + 7; long long int hashes[1000000]; long long int powers[1000000]; int n; long long getHash(int start, int ending){ if(start == 0) return hashes[ending]; return ((hashes[ending] - (hashes[start - 1] * powers[ending - start+1])%m)%m + m)%m; } //aanbeana int main(){ int t; string s; cin >> t; while(t--){ cin >> s; n = s.size(); memset(hashes, 0, sizeof(hashes)); memset(powers, 0, sizeof(powers)); hashes[0] = s[0]-'a'+1; powers[0] = 1; for(int i = 1; i < s.size(); ++i){ hashes[i] = (((__int128)hashes[i-1]*p)%m + (s[i]-'a' + 1))%m; powers[i] = ((__int128)powers[i-1]*p)%m; } int ans = 1; int MaxLeft = -1; int MaxRight = s.size(); int left = 0; int right = s.size()-1; while(left < right){ if(getHash(MaxLeft+1, left) == getHash(right, MaxRight-1)){ ans+=2; MaxLeft = left; MaxRight = right; } left++; right--; } if(MaxLeft+1 == MaxRight)ans--; cout << ans << endl;; } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 15956 KB | Output is correct |
2 | Correct | 22 ms | 15956 KB | Output is correct |
3 | Correct | 14 ms | 15956 KB | Output is correct |
4 | Correct | 22 ms | 15956 KB | Output is correct |
5 | Correct | 25 ms | 15956 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 15956 KB | Output is correct |
2 | Correct | 22 ms | 15956 KB | Output is correct |
3 | Correct | 14 ms | 15956 KB | Output is correct |
4 | Correct | 22 ms | 15956 KB | Output is correct |
5 | Correct | 25 ms | 15956 KB | Output is correct |
6 | Correct | 22 ms | 15956 KB | Output is correct |
7 | Correct | 14 ms | 15956 KB | Output is correct |
8 | Correct | 21 ms | 15920 KB | Output is correct |
9 | Correct | 25 ms | 15956 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 15956 KB | Output is correct |
2 | Correct | 22 ms | 15956 KB | Output is correct |
3 | Correct | 14 ms | 15956 KB | Output is correct |
4 | Correct | 22 ms | 15956 KB | Output is correct |
5 | Correct | 25 ms | 15956 KB | Output is correct |
6 | Correct | 22 ms | 15956 KB | Output is correct |
7 | Correct | 14 ms | 15956 KB | Output is correct |
8 | Correct | 21 ms | 15920 KB | Output is correct |
9 | Correct | 25 ms | 15956 KB | Output is correct |
10 | Correct | 27 ms | 16020 KB | Output is correct |
11 | Correct | 17 ms | 16036 KB | Output is correct |
12 | Correct | 26 ms | 15956 KB | Output is correct |
13 | Correct | 26 ms | 16028 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 15956 KB | Output is correct |
2 | Correct | 22 ms | 15956 KB | Output is correct |
3 | Correct | 14 ms | 15956 KB | Output is correct |
4 | Correct | 22 ms | 15956 KB | Output is correct |
5 | Correct | 25 ms | 15956 KB | Output is correct |
6 | Correct | 22 ms | 15956 KB | Output is correct |
7 | Correct | 14 ms | 15956 KB | Output is correct |
8 | Correct | 21 ms | 15920 KB | Output is correct |
9 | Correct | 25 ms | 15956 KB | Output is correct |
10 | Correct | 27 ms | 16020 KB | Output is correct |
11 | Correct | 17 ms | 16036 KB | Output is correct |
12 | Correct | 26 ms | 15956 KB | Output is correct |
13 | Correct | 26 ms | 16028 KB | Output is correct |
14 | Correct | 440 ms | 26772 KB | Output is correct |
15 | Correct | 220 ms | 22168 KB | Output is correct |
16 | Correct | 420 ms | 26392 KB | Output is correct |
17 | Correct | 230 ms | 21704 KB | Output is correct |