結果
問題 | No.2606 Mirror Relay |
ユーザー | novaandcabral |
提出日時 | 2024-04-13 07:49:36 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,506 bytes |
コンパイル時間 | 1,156 ms |
コンパイル使用メモリ | 93,972 KB |
実行使用メモリ | 48,652 KB |
最終ジャッジ日時 | 2024-10-02 23:56:44 |
合計ジャッジ時間 | 3,813 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 1 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 | 1 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 | 1 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 | 1 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 | 3 ms
5,376 KB |
testcase_23 | AC | 2 ms
5,376 KB |
testcase_24 | AC | 3 ms
5,376 KB |
testcase_25 | AC | 2 ms
5,376 KB |
testcase_26 | AC | 2 ms
5,376 KB |
testcase_27 | AC | 2 ms
5,376 KB |
testcase_28 | AC | 2 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 | 2 ms
5,376 KB |
testcase_33 | AC | 2 ms
5,376 KB |
testcase_34 | AC | 1 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 | 13 ms
5,376 KB |
testcase_40 | AC | 12 ms
5,376 KB |
testcase_41 | AC | 12 ms
5,376 KB |
testcase_42 | AC | 12 ms
5,376 KB |
testcase_43 | AC | 12 ms
5,376 KB |
testcase_44 | AC | 12 ms
5,376 KB |
testcase_45 | AC | 12 ms
5,376 KB |
testcase_46 | AC | 12 ms
5,376 KB |
testcase_47 | AC | 11 ms
5,376 KB |
testcase_48 | AC | 12 ms
5,376 KB |
testcase_49 | WA | - |
testcase_50 | WA | - |
testcase_51 | WA | - |
testcase_52 | WA | - |
testcase_53 | WA | - |
testcase_54 | WA | - |
testcase_55 | WA | - |
testcase_56 | WA | - |
testcase_57 | WA | - |
testcase_58 | WA | - |
testcase_59 | WA | - |
testcase_60 | WA | - |
testcase_61 | AC | 12 ms
5,376 KB |
testcase_62 | AC | 12 ms
5,376 KB |
testcase_63 | WA | - |
testcase_64 | AC | 12 ms
5,376 KB |
testcase_65 | WA | - |
testcase_66 | AC | 12 ms
5,376 KB |
testcase_67 | WA | - |
testcase_68 | WA | - |
testcase_69 | WA | - |
testcase_70 | AC | 2 ms
5,376 KB |
testcase_71 | AC | 2 ms
5,376 KB |
testcase_72 | AC | 2 ms
5,376 KB |
ソースコード
#include <iostream> #include <vector> #include <unordered_map> using namespace std; class PalindromicTree { private: vector<char> st; vector<int> length; vector<int> parent; vector<int> count; vector<unordered_map<char, int>> link; int lastNodeIdx; public: PalindromicTree() { st.push_back(0); length.push_back(-1); length.push_back(0); parent.push_back(0); parent.push_back(0); count.push_back(0); count.push_back(0); link.push_back({}); link.push_back({}); lastNodeIdx = 0; } void add(char v) { st.push_back(v); int prevNodeIdx = lastNodeIdx; int nextNodeIdx = lastNodeIdx; while (true) { int head = length[nextNodeIdx] + 2; if (head <= st.size() && st[st.size() - head] == st.back()) { break; } nextNodeIdx = parent[nextNodeIdx]; } int nextLen = length[nextNodeIdx] + 2; if (link[nextNodeIdx].count(v)) { lastNodeIdx = link[nextNodeIdx][v]; count[lastNodeIdx]++; return; } lastNodeIdx = length.size(); length.push_back(nextLen); if (nextLen == 1) { parent.push_back(1); } else { int prevNodeIdx = parent[nextNodeIdx]; while (true) { int head = length[prevNodeIdx] + 2; if (head <= st.size() && st[st.size() - head] == st.back()) { break; } prevNodeIdx = parent[prevNodeIdx]; } parent.push_back(link[prevNodeIdx][v]); } count.push_back(1); link[nextNodeIdx][v] = lastNodeIdx; link.push_back({}); } int maxScore() { int nodeCount = length.size(); vector<int> score(nodeCount, 0); vector<int> tempCount = count; for (int i = nodeCount - 1; i >= 2; i--) { tempCount[parent[i]] += tempCount[i]; } for (int i = 2; i < nodeCount; i++) { score[i] = score[parent[i]] + length[i] * tempCount[i]; } int maxScore = 0; for (int s : score) { maxScore = max(maxScore, s); } return maxScore; } }; int main() { string s; cin >> s; PalindromicTree pt; for (int i = s.length() - 1; i >= 0; i--) { pt.add(s[i]); } cout << pt.maxScore() << endl; return 0; }