Submission #941226

#TimeUsernameProblemLanguageResultExecution timeMemory
941226wiiPalindromes (APIO14_palindrome)C++17
100 / 100
36 ms69092 KiB
#include <bits/stdc++.h> using namespace std; typedef double db; typedef long long ll; typedef long double ld; #define int ll typedef pair<int, int> pii; #define lx (id << 1) #define rx (lx | 1) #define gcd __gcd #define pb push_back #define all(x) (x).begin(), (x).end() #define bit(i, mask) ((mask) >> (i) & 1) #define reset(x, val) memset(x, val, sizeof(x)) #define foru(i,a,b) for(int i = (a); i <= (b); ++i) #define ford(i,a,b) for(int i = (a); i >= (b); --i) #define FastIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); template<typename T> bool maximize(T &res, const T &val) { if (res < val) { res = val; return true; } return false; } template<typename T> bool minimize(T &res, const T &val) { if (val < res) { res = val; return true; } return false; } const ll Linf = 0x3f3f3f3f3f3f3f3f; const int Inf = 0x3f3f3f3f; const ll Mod = 1e9 + 7; const ll Mod2 = ll(1e9) + 9; const int Lim = 1e6 + 5; const int inv6 = 166666668; /// ====*====*====*====*====*====*====*====*====*====*====*====*====*====*====*====*==== const int base = 3; const int N = 3e5 + 5; const int K = log2(N) + 1; const int dx[] = {+1, -1, 0, 0}; const int dy[] = {0, 0, +1, -1}; const int block_size = sqrt(2e9) + 2; struct Node { int len; int suffLink; int num; int nxt[26]; }; int num; int len; int suff; Node tree[N]; string str; bool addLetter(int pos) { int cur = suff, curLen = 0; int let = str[pos] - 'a'; while (true) { curLen = tree[cur].len; if (pos - 1 - curLen >= 0 && str[pos - 1 - curLen] == str[pos]) break; cur = tree[cur].suffLink; } if (tree[cur].nxt[let]) { suff = tree[cur].nxt[let]; return false; } ++num; suff = num; tree[num].len = tree[cur].len + 2; tree[cur].nxt[let] = num; if (tree[num].len == 1) { tree[num].suffLink = 2; return true; } while (true) { cur = tree[cur].suffLink; curLen = tree[cur].len; if (pos - 1 - curLen >= 0 && str[pos - 1 - curLen] == str[pos]) { tree[num].suffLink = tree[cur].nxt[let]; break; } } return true; } void solve() { cin >> str; num = 2; suff = 2; tree[1].len = -1; tree[2].suffLink = 1; tree[2].len = 0; tree[2].suffLink = 1; for (int i = 0; i < str.size(); ++i) { addLetter(i); ++tree[suff].num; } int ans = 0; for (int i = num; i >= 3; --i) { tree[tree[i].suffLink].num += tree[i].num; maximize(ans, tree[i].len * tree[i].num); } cout << ans; } signed main() { FastIO; #define task "test" if (fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } #define task "palindrome" if (fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } int ntest = 1; // cin >> ntest; while (ntest--) { //cout << "Case " << q << ": " << "\n"; solve(); cout << "\n"; } return 0; } /** /\_/\ * (= ._.) * / >TL \>AC **/

Compilation message (stderr)

palindrome.cpp:124: warning: "task" redefined
  124 |     #define task "palindrome"
      | 
palindrome.cpp:118: note: this is the location of the previous definition
  118 |     #define task "test"
      | 
palindrome.cpp: In function 'void solve()':
palindrome.cpp:100:23: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |     for (int i = 0; i < str.size(); ++i) {
      |                     ~~^~~~~~~~~~~~
palindrome.cpp: In function 'int main()':
palindrome.cpp:120:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  120 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
palindrome.cpp:121:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  121 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
palindrome.cpp:126:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  126 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
palindrome.cpp:127:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  127 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...