제출 #921425

#제출 시각아이디문제언어결과실행 시간메모리
921425AVIJIT_BISWAS회문 (APIO14_palindrome)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long struct PalindromicTree { struct node { int nxt[26], len, link, occ; }; string s; vector<node> t; int sz, last; PalindromicTree() {} PalindromicTree(string _s) { s = _s; int n = s.size(); t.clear(); t.resize(n + 9); sz = 2, last = 2; t[1].len = -1, t[1].link = 1; t[2].len = 0, t[2].link = 1; } int extend(int pos) { // returns 1 if it creates a new palindrome int cur = last, curlen = 0; int ch = s[pos] - 'a'; while (1) { curlen = t[cur].len; if (pos - 1 - curlen >= 0 && s[pos - 1 - curlen] == s[pos]) break; cur = t[cur].link; } if (t[cur].nxt[ch]) { last = t[cur].nxt[ch]; return 0; } sz++; last = sz; t[sz].len = t[cur].len + 2; t[cur].nxt[ch] = sz; ++t[last].occ; if (t[sz].len == 1) { t[sz].link = 2; return 1; } while (1) { cur = t[cur].link; curlen = t[cur].len; if (pos - 1 - curlen >= 0 && s[pos - 1 - curlen] == s[pos]) { t[sz].link = t[cur].nxt[ch]; break; } } dp[sz] = dp[t[sz].link] + 1; return 1; } }T; void solve() { string s; cin >> s; T = PalindromicTree(s); int n = s.size(); for(int i = 0; i < n; i++){ T.extend(i); } ll ans = 0; for(int i = T.sz; i > 2; i--) { T.t[T.t[i].link].occ += T.t[i].occ; ans = max(ans, 1ll * T.t[i].occ * T.t[i].len); } cout << ans << '\n'; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr);int t = 1; #ifndef ONLINE_JUDGE freopen("output.txt", "w", stderr); #endif // cin >> t; for(int i = 1; i <= t; i++){ //cout << "-----Case:" << i << "-----\n"; solve(); } return 0; }

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

palindrome.cpp: In member function 'int PalindromicTree::extend(int)':
palindrome.cpp:53:5: error: 'dp' was not declared in this scope
   53 |     dp[sz] = dp[t[sz].link] + 1;
      |     ^~
palindrome.cpp: In function 'int32_t main()':
palindrome.cpp:84:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |     freopen("output.txt", "w", stderr);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~