Submission #716775

#TimeUsernameProblemLanguageResultExecution timeMemory
716775vjudge1회문 (APIO14_palindrome)C++17
8 / 100
1073 ms11700 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define sz(v) (int)v.size() #define x first #define y second #define nl "\n" using namespace std; const int N = (int)1e3 + 7; const int M = (int)2e6 + 5e5 + 7; const ll MOD = (ll)1e9; const int inf = (int)1e9 + 7; const int B = (int)390; const ll INF = (ll)1e18 + 7; pair<int, int> dir[] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}}; bool bit(int mask, int i) { return (mask >> i & 1); } int sum(int x, int y) { x += y; if(x >= MOD) x -= MOD; return x; } int mult(int x, int y) { return 1ll * x * y % MOD; } vector<int> z_function (string s) { int n = sz(s); vector<int> z(n); for (int i = 1, l = 0, r = 0; i < n; ++i) { if (i <= r) z[i] = min(r - i + 1, z[i - l]); while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i]; if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1; } return z; } string s; int cnt[N][N]; bool is[N][N]; void solve() { cin >> s; int ans = 0, n = sz(s); s = '#' + s; for(int i = 1; i <= n; ++i) { is[i][i] = 1; is[i][i - 1] = 1; } for(int len = 2; len <= n; ++len) { for(int i = 1; i <= n; ++i) { int j = i + len - 1; is[i][j] = (s[i] == s[j] && is[i + 1][j - 1]); } } for(int i = 1; i <= n; ++i) { string cur; for(int j = i; j <= n; ++j) { cur += s[j]; string t = cur; t += '#'; t += s; vector<int> z = z_function(t); for(auto x : z) { if(x == j - i + 1) cnt[i][j]++; } } } for(int i = 1; i <= n; ++i) { for(int j = i; j <= n; ++j) { if(!is[i][j]) continue; ans = max(ans, (j - i + 1) * cnt[i][j]); } } cout << ans << nl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); //freopen("palindrome.in", "r", stdin); //freopen("palindrome.out", "w", stdout); int test = 1; //cin >> test; for(int i = 1; i <= test; ++i) { //cout << "Case " << i << ":\n"; solve(); } return 0; } /* possible causes of error : * array bounds * int overflow * special case (n == 1?) * haven't clean something * wrong N | M | inf | INF | MOD * try to write brute force to find test * don't waste time * don't write bullshit * solution is easy */
#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...