結果
問題 | No.2606 Mirror Relay |
ユーザー | Misuki |
提出日時 | 2024-01-13 21:06:00 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 39 ms / 2,000 ms |
コード長 | 3,277 bytes |
コンパイル時間 | 2,722 ms |
コンパイル使用メモリ | 214,856 KB |
実行使用メモリ | 50,304 KB |
最終ジャッジ日時 | 2024-09-28 01:47:28 |
合計ジャッジ時間 | 5,108 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 2 ms
5,376 KB |
testcase_15 | AC | 2 ms
5,376 KB |
testcase_16 | AC | 2 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 2 ms
5,376 KB |
testcase_20 | AC | 3 ms
5,376 KB |
testcase_21 | AC | 2 ms
5,376 KB |
testcase_22 | AC | 2 ms
5,376 KB |
testcase_23 | AC | 2 ms
5,376 KB |
testcase_24 | AC | 2 ms
5,376 KB |
testcase_25 | AC | 3 ms
5,376 KB |
testcase_26 | AC | 2 ms
5,376 KB |
testcase_27 | AC | 3 ms
5,376 KB |
testcase_28 | AC | 3 ms
5,376 KB |
testcase_29 | AC | 2 ms
5,376 KB |
testcase_30 | AC | 2 ms
5,376 KB |
testcase_31 | AC | 2 ms
5,376 KB |
testcase_32 | AC | 3 ms
5,376 KB |
testcase_33 | AC | 3 ms
5,376 KB |
testcase_34 | AC | 2 ms
5,376 KB |
testcase_35 | AC | 2 ms
5,376 KB |
testcase_36 | AC | 2 ms
5,376 KB |
testcase_37 | AC | 2 ms
5,376 KB |
testcase_38 | AC | 2 ms
5,376 KB |
testcase_39 | AC | 6 ms
5,376 KB |
testcase_40 | AC | 6 ms
5,376 KB |
testcase_41 | AC | 6 ms
5,376 KB |
testcase_42 | AC | 6 ms
5,376 KB |
testcase_43 | AC | 6 ms
5,376 KB |
testcase_44 | AC | 7 ms
5,376 KB |
testcase_45 | AC | 6 ms
5,376 KB |
testcase_46 | AC | 6 ms
5,376 KB |
testcase_47 | AC | 7 ms
5,376 KB |
testcase_48 | AC | 6 ms
5,376 KB |
testcase_49 | AC | 15 ms
15,744 KB |
testcase_50 | AC | 15 ms
16,896 KB |
testcase_51 | AC | 15 ms
17,664 KB |
testcase_52 | AC | 14 ms
13,392 KB |
testcase_53 | AC | 16 ms
17,732 KB |
testcase_54 | AC | 15 ms
16,380 KB |
testcase_55 | AC | 22 ms
27,108 KB |
testcase_56 | AC | 15 ms
16,368 KB |
testcase_57 | AC | 15 ms
14,208 KB |
testcase_58 | AC | 17 ms
19,704 KB |
testcase_59 | AC | 6 ms
5,376 KB |
testcase_60 | AC | 6 ms
5,376 KB |
testcase_61 | AC | 6 ms
5,376 KB |
testcase_62 | AC | 6 ms
5,376 KB |
testcase_63 | AC | 6 ms
5,376 KB |
testcase_64 | AC | 7 ms
5,376 KB |
testcase_65 | AC | 6 ms
5,376 KB |
testcase_66 | AC | 6 ms
5,376 KB |
testcase_67 | AC | 6 ms
5,376 KB |
testcase_68 | AC | 6 ms
5,376 KB |
testcase_69 | AC | 39 ms
50,304 KB |
testcase_70 | AC | 2 ms
5,376 KB |
testcase_71 | AC | 2 ms
5,376 KB |
testcase_72 | AC | 2 ms
5,376 KB |
ソースコード
#pragma GCC optimize("O2") #include <algorithm> #include <array> #include <bit> #include <bitset> #include <cassert> #include <cctype> #include <cfenv> #include <cfloat> #include <chrono> #include <cinttypes> #include <climits> #include <cmath> #include <compare> #include <complex> #include <concepts> #include <cstdarg> #include <cstddef> #include <cstdint> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <fstream> #include <functional> #include <initializer_list> #include <iomanip> #include <ios> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <map> #include <memory> #include <new> #include <numbers> #include <numeric> #include <ostream> #include <queue> #include <random> #include <ranges> #include <set> #include <span> #include <sstream> #include <stack> #include <streambuf> #include <string> #include <tuple> #include <type_traits> #include <variant> #define int ll #define INT128_MAX (__int128)(((unsigned __int128) 1 << ((sizeof(__int128) * __CHAR_BIT__) - 1)) - 1) #define INT128_MIN (-INT128_MAX - 1) #ifdef DEBUG #define dbg(x) cout << (#x) << " = " << x << '\n' #else #define dbg(x) #endif namespace R = std::ranges; namespace V = std::views; using namespace std; using ll = long long; using ull = unsigned long long; using ldb = long double; //#define double ldb template<class T, size_t N> ostream& operator<<(ostream& os, const array<T, N> &arr) { for(const T &X : arr) os << X << ' '; return os; } template<class T> ostream& operator<<(ostream& os, const vector<T> &vec) { for(const T &X : vec) os << X << ' '; return os; } template<class T> ostream& operator<<(ostream& os, const set<T> &s) { for(const T &x : s) os << x << ' '; return os; } /** * template name: palindromicTree * author: Misuki * last update: 2024/01/13 * verify: yukicoder - No.2606 Mirror Relay */ template<unsigned sigma = 26, char base = 'a'> struct palindromicTree { vector<int> len, link; vector<ll> freq; vector<array<int, sigma>> go; palindromicTree(string s) { array<int, sigma> unit; fill(unit.begin(), unit.end(), -1); len = link = {-1, 0}, go = {unit, unit}, freq = {0, 0}; len.reserve(ssize(s) + 2); link.reserve(ssize(s) + 2); go.reserve(ssize(s) + 2); freq.reserve(ssize(s) + 2); int v = 0; for(int i = 0; i < ssize(s); i++) { while(len[v] == i or s[i - len[v] - 1] != s[i]) v = link[v]; if (go[v][s[i] - base] == -1) { go[v][s[i] - base] = ssize(len); len.emplace_back(len[v] + 2); freq.emplace_back(); go.emplace_back(unit); int u = link[v]; while(u != -1 and s[i - len[u] - 1] != s[i]) u = link[u]; link.emplace_back(u == -1 ? 1 : go[u][s[i] - base]); } v = go[v][s[i] - base]; freq[v]++; } for(int i = ssize(len) - 1; i > 0; i--) freq[link[i]] += freq[i]; freq[0] = freq[1] = 0; } }; signed main() { ios::sync_with_stdio(false), cin.tie(NULL); string s; cin >> s; palindromicTree pt(s); vector<ll> dp(ssize(pt.len)); for(int i = 2; i < ssize(pt.len); i++) dp[i] = dp[pt.link[i]] + pt.freq[i] * pt.len[i]; cout << R::max(dp) << '\n'; return 0; }