| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 366684 | penguinhacker | Palindromic Partitions (CEOI17_palindromic) | C++14 | 448 ms | 36104 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
const int MOD = 1e9 + 7;
namespace Hashing {
mt19937 rng((uint32_t) chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<int> BDIST(0.1 * MOD, 0.9 * MOD);
const ar<int, 2> base = {BDIST(rng), BDIST(rng)};
ar<int, 2> operator+ (ar<int, 2> a, ar<int, 2> b) {
for (int i = 0; i < 2; ++i)
if ((a[i] += b[i]) >= MOD)
a[i] -= MOD;
return a;
}
ar<int, 2> operator- (ar<int, 2> a, ar<int, 2> b) {
for (int i = 0; i < 2; ++i)
if ((a[i] -= b[i]) < 0)
a[i] += MOD;
return a;
}
ar<int, 2> operator* (ar<int, 2> a, ar<int, 2> b) {
for (int i = 0; i < 2; ++i)
a[i] = (ll)a[i] * b[i] % MOD;
return a;
}
ar<int, 2> make_hash(char c) {
return {c, c};
}
vector<ar<int, 2>> pows = {{1, 1}};
void extend(int len) {
while(pows.size() <= len)
pows.push_back(base * pows.back());
}
struct hstring {
string s;
vector<ar<int, 2>> pre = {{0, 0}};
void add(string t) {
s += t;
for (char c : t)
pre.push_back(base * pre.back() + make_hash(c));
}
ar<int, 2> hash(int l, int r) {
assert(0 <= l && l <= r && r < s.size());
int len = r - l + 1;
extend(len);
return pre[r + 1] - pows[len] * pre[l];
}
};
}
using namespace Hashing;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t; cin >> t;
while(t--) {
string s; cin >> s;
int n = s.size();
hstring hs; hs.add(s);
int last = 0;
int ans = 0;
for (int i = 0; i < n / 2; ++i) {
if (hs.hash(last, i) == hs.hash(n - i - 1, n - last - 1)) {
last = i + 1;
ans += 2;
}
}
ans += 2 * last < n;
cout << ans << "\n";
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
