제출 #493436

#제출 시각아이디문제언어결과실행 시간메모리
493436JovanB회문 (APIO14_palindrome)C++17
0 / 100
2 ms1236 KiB
#include <bits/stdc++.h> #define PRINT(x) cerr<<#x<<'='<<x<<endl; using namespace std; struct PalTree { #define P_SIGMA 26 #define FIRST_NODE 1 #define SECOND_NODE 2 struct Node { int len, cnt, dub, slink; int to[P_SIGMA]; Node() { len = cnt = dub = slink = 0; for(int i = 0; i < P_SIGMA; i++) to[i] = 0; } Node(int _len, int _cnt, int _dub, int _slink) { len = _len; cnt = _cnt; dub = _dub; slink = _slink; for(int i = 0; i < P_SIGMA; i++) to[i] = 0; } }; string s; vector<Node> pt; int suff; int toidx(char c) { return c-'a'; } void addLetter(char c) { s += c; int len = s.size(); assert(0 <= len-2-pt[suff].len); while(c != s[len-2-pt[suff].len]) { suff = pt[suff].slink; } int nd = pt[suff].to[toidx(c)]; if(nd == 0) { nd = pt.size(); pt[suff].to[toidx(c)] = nd; pt.push_back(Node(pt[suff].len+2, 0, 0, 0)); if(suff == FIRST_NODE) { pt[nd].slink = SECOND_NODE; } else { int u = pt[suff].slink; while(c != s[len-2-pt[u].len]) { u = pt[u].slink; } pt[nd].slink = pt[u].to[toidx(c)]; } pt[nd].dub = pt[pt[nd].slink].dub+1; } pt[nd].cnt++; suff = nd; } void calcCnt() { for(int i = pt.size()-1; i > 2; i--) { pt[pt[i].slink].cnt += pt[i].cnt; } } void init() { pt.clear(); s = ""; suff = 1; pt.push_back(Node(0, 0, 0, 0)); pt.push_back(Node(-1, 0, 0, FIRST_NODE)); ///first node pt.push_back(Node(0, 0, 0, FIRST_NODE)); ///second node } Node &operator[](int idx) { if(idx >= pt.size()) { cerr << "Index out of bounds" <<endl; return pt[0]; } return pt[idx]; } }; PalTree pt; int main() { ios::sync_with_stdio(false); cin.tie(0); string s; cin >> s; pt.init(); for(auto x : s) { pt.addLetter(x); } pt.calcCnt(); long long rez = 0; for(int i = pt.pt.size()-1; i > 2; i--) { rez = max(rez, (long long) pt[i].len*pt[i].cnt); } cout << rez << endl; return 0; }

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

palindrome.cpp: In member function 'PalTree::Node& PalTree::operator[](int)':
palindrome.cpp:61:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<PalTree::Node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |         if(idx >= pt.size()) {
      |            ~~~~^~~~~~~~~~~~
#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...