# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
223440 | 2020-04-15T09:22:57 Z | dantoh000 | Lampice (COCI19_lampice) | C++14 | 5000 ms | 9640 KB |
#include <bits/stdc++.h> using namespace std; int n; vector<int> adjlist[50005]; int ans = 0; string s; void maxlpalindrome(vector<char> s){ int n = s.size(); ///For odd-length palindrome vector<int> d1(n); for (int i = 0, l = 0, r = -1; i < n; i++) { int k = (i > r) ? 1 : min(d1[l + r - i], r - i + 1); while (0 <= i - k && i + k < n && s[i - k] == s[i + k]) { k++; } d1[i] = k--; if (i + k > r) { l = i - k; r = i + k; } } ///For even-length palindromes vector<int> d2(n); for (int i = 0, l = 0, r = -1; i < n; i++) { int k = (i > r) ? 0 : min(d2[l + r - i + 1], r - i + 1); while (0 <= i - k - 1 && i + k < n && s[i - k - 1] == s[i + k]) { k++; } d2[i] = k--; if (i + k > r) { l = i - k - 1; r = i + k ; } } for (int i = 0; i < n; i++){ ans = max(ans,max(2*d1[i]-1,2*d2[i])); } } vector<char> st; void dfs(int u, int p){ st.push_back(s[u-1]); for (auto v : adjlist[u]){ if (v == p) continue; dfs(v,u); } if (adjlist[u].size() == 1) maxlpalindrome(st); st.pop_back(); } int main(){ scanf("%d",&n); cin >> s; for (int i = 0; i < n-1; i++){ int a,b; scanf("%d%d",&a,&b); adjlist[a].push_back(b); adjlist[b].push_back(a); } for (int i = 1; i <= n; i++){ st.clear(); dfs(i,-1); } printf("%d",ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 29 ms | 1536 KB | Output is correct |
2 | Correct | 108 ms | 1536 KB | Output is correct |
3 | Correct | 834 ms | 1656 KB | Output is correct |
4 | Correct | 2599 ms | 1668 KB | Output is correct |
5 | Incorrect | 5 ms | 1536 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 5077 ms | 9640 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 5084 ms | 5948 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 29 ms | 1536 KB | Output is correct |
2 | Correct | 108 ms | 1536 KB | Output is correct |
3 | Correct | 834 ms | 1656 KB | Output is correct |
4 | Correct | 2599 ms | 1668 KB | Output is correct |
5 | Incorrect | 5 ms | 1536 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |