結果
問題 |
No.2234 palindromer
|
ユーザー |
![]() |
提出日時 | 2025-03-22 21:41:28 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,030 bytes |
コンパイル時間 | 6,093 ms |
コンパイル使用メモリ | 211,144 KB |
実行使用メモリ | 7,772 KB |
最終ジャッジ日時 | 2025-03-22 21:41:35 |
合計ジャッジ時間 | 7,112 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 13 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ULL = unsigned long long; constexpr const ULL B1 = 911382629, B2 = 357147329; constexpr const int N = 5e5 + 3; ULL p1[N], p2[N], h1[N], h2[N], hr1[N], hr2[N]; int main() { cin.tie(nullptr)->sync_with_stdio(false); string s; cin >> s; int n = s.size(); if(n == 1) { cout << s << endl; return 0; } p1[0] = p2[0] = 1; for(int i = 1; i <= n; ++i) { p1[i] = p1[i - 1] * B1; p2[i] = p2[i - 1] * B2; } for(int i = 0; i < n; ++i) { h1[i + 1] = h1[i] * B1 + s[i]; h2[i + 1] = h2[i] * B2 + s[i]; } string sr(s.crbegin(), s.crend()); for(int i = 0; i < n; ++i) { hr1[i + 1] = hr1[i] * B1 + sr[i]; hr2[i + 1] = hr2[i] * B2 + sr[i]; } int id = n; for(int i = 0; i < n; ++i) { int l = n - i; ULL Hs1 = h1[n] - h1[i] * p1[l], Hr1 = hr1[l]; ULL Hs2 = h2[n] - h2[i] * p2[l], Hr2 = hr2[l]; if(Hs1 == Hr1 && Hs2 == Hr2) { id = i; break; } } string ans = s.substr(0, id); reverse(ans.begin(), ans.end()); cout << s << ans << endl; return 0; }