# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
223447 | 2020-04-15T09:25:48 Z | dantoh000 | Lampice (COCI19_lampice) | C++14 | 1341 ms | 10496 KB |
#include <bits/stdc++.h> using namespace std; int n; vector<int> adjlist[50005]; int ans = 0; string s; void maxlpalindrome(vector<char> s){ //for (auto x : s) printf("%c",x); //printf(" processing\n"); int n = s.size(); ///For odd-length palindrome vector<int> d1(n,0); 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,0); 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]); int k = 0; for (auto v : adjlist[u]){ if (v == p) continue; k = 1; dfs(v,u); } if (k == 0) 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++){ if (adjlist[i].size() == 1){ st.clear(); dfs(i,-1); } } printf("%d",ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 1536 KB | Output is correct |
2 | Correct | 59 ms | 1536 KB | Output is correct |
3 | Correct | 301 ms | 1660 KB | Output is correct |
4 | Correct | 925 ms | 1656 KB | Output is correct |
5 | Incorrect | 5 ms | 1536 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 30 ms | 8744 KB | Output is correct |
2 | Correct | 31 ms | 9504 KB | Output is correct |
3 | Correct | 32 ms | 9744 KB | Output is correct |
4 | Correct | 33 ms | 10112 KB | Output is correct |
5 | Correct | 34 ms | 10496 KB | Output is correct |
6 | Correct | 35 ms | 10496 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 977 ms | 5240 KB | Output is correct |
2 | Correct | 626 ms | 5240 KB | Output is correct |
3 | Correct | 1341 ms | 5844 KB | Output is correct |
4 | Correct | 997 ms | 6076 KB | Output is correct |
5 | Correct | 559 ms | 4472 KB | Output is correct |
6 | Correct | 616 ms | 4472 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 1536 KB | Output is correct |
2 | Correct | 59 ms | 1536 KB | Output is correct |
3 | Correct | 301 ms | 1660 KB | Output is correct |
4 | Correct | 925 ms | 1656 KB | Output is correct |
5 | Incorrect | 5 ms | 1536 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |