(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

제출 #1117468

#제출 시각아이디문제언어결과실행 시간메모리
1117468mat_jur회문 (APIO14_palindrome)C++17
0 / 100
116 ms131072 KiB
#include <bits/stdc++.h> using namespace std; #ifdef DEBUG auto&operator<<(auto &o, pair<auto, auto> p) {o << "(" << p.first << ", " << p.second << ")"; return o;} auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{"; for(auto e : x) o<<e<<", "; return o<<"}";} #define debug(X) cerr << "["#X"]: " << X << '\n'; #else #define cerr if(0)cout #define debug(X) ; #endif using ll = long long; #define all(v) (v).begin(), (v).end() #define ssize(x) int(x.size()) #define fi first #define se second #define mp make_pair #define eb emplace_back const int A = 27; struct trie_node { int depth; trie_node* parent; trie_node* e[A]; int cnt; trie_node() { depth = 0; parent = nullptr; for (int i = 0; i < A; ++i) e[i] = nullptr; cnt = 0; } }; void add_edge(trie_node *v, char c) { // assert(v != nullptr); int x = c - 'a'; if (v->e[x] != nullptr) return; trie_node *u = v->e[x] = new trie_node; u->depth = v->depth + 1; u->parent = v; } ll dfs(trie_node *v) { ll res = 0; for (int i = 0; i < A; ++i) { if (v->e[i] != nullptr) { res = max(res, dfs(v->e[i])); v->cnt += v->e[i]->cnt; #ifdef DEBUG delete v->e[i]; #endif } } return max(res, ll(v->cnt) * ll(v->depth - 1)); } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; int n = ssize(s); char filler = 'z' + 1; string tmp; tmp.push_back(filler); for (char x : s) { tmp.push_back(x); tmp.push_back(filler); } s = tmp; n = ssize(s); debug(s); vector<int> r(n); int f = 0; r[0] = 1; vector<trie_node*> Node(n+1); Node[0] = new trie_node; add_edge(Node[0], s[0]); Node[1] = Node[0]->e[s[0]-'a']; for (int i = 1; i < n; ++i) { int parent = 0; r[i] = 0; if (f + r[f] - 1 >= i) { int sym = 2*f - i; if (sym >= 0) r[i] = max(r[i], min(r[sym], sym - (f - r[f]))); parent = sym+1; } int v = i+1; Node[v] = Node[parent]; while (Node[v]->depth != r[i]) Node[v] = Node[v]->parent; while (i - r[i] >= 0 && i + r[i] < n && s[i-r[i]] == s[i+r[i]]) { add_edge(Node[v], s[i+r[i]]); Node[v] = Node[v]->e[s[i+r[i]]-'a']; r[i]++; } Node[v]->cnt++; if (i + r[i] >= f + r[f]) f = i; } ll res = dfs(Node[0]); #ifdef DEBUG delete Node[0]; #endif // cout << res << '\n'; cout << "OK \n"; return 0; }

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

palindrome.cpp: In function 'int main()':
palindrome.cpp:113:5: warning: unused variable 'res' [-Wunused-variable]
  113 |  ll res = dfs(Node[0]);
      |     ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...