제출 #205388

#제출 시각아이디문제언어결과실행 시간메모리
205388dolphingarlicPalindromic Partitions (CEOI17_palindromic)C++14
100 / 100
50 ms20784 KiB
#include <bits/stdc++.h> #define FOR(i, x, y) for (int i = x; i < y; i++) typedef unsigned long long ll; using namespace std; const ll P = 29; ll pw[1000001]{1}; int main() { ios_base::sync_with_stdio(0); cin.tie(0); FOR(i, 1, 1000001) pw[i] = pw[i - 1] * P; int n; cin >> n; while (n--) { string s; cin >> s; int l = 0, r = s.size() - 1, pl = 0, pr = s.size() - 1; int ans = 0; ll hsh_l = 0, hsh_r = 0; while (l < r) { hsh_l = hsh_l * P + (s[l++] - 'a' + 1); hsh_r += pw[pr - r] * (s[r--] - 'a' + 1); if (hsh_l == hsh_r) { FOR(i, 0, l - pl) if (s[pl + i] != s[r + i]) continue; ans += 2; hsh_l = hsh_r = 0; pl = l, pr = r; } } if (l == r || pl != l) ans++; cout << ans << '\n'; } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

palindromic.cpp: In function 'int main()':
palindromic.cpp:26:39: warning: operation on 'r' may be undefined [-Wsequence-point]
             hsh_r += pw[pr - r] * (s[r--] - 'a' + 1);
                                      ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...