# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
223450 | 2020-04-15T09:26:35 Z | dantoh000 | Lampice (COCI19_lampice) | C++14 | 5000 ms | 9856 KB |
#include <bits/stdc++.h> using namespace std; int n; vector<int> adjlist[50005]; int ans = 1; 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 | 18 ms | 1536 KB | Output is correct |
2 | Correct | 63 ms | 1536 KB | Output is correct |
3 | Correct | 289 ms | 1536 KB | Output is correct |
4 | Correct | 924 ms | 1640 KB | Output is correct |
5 | Correct | 6 ms | 1536 KB | Output is correct |
6 | Correct | 5 ms | 1536 KB | Output is correct |
7 | Correct | 5 ms | 1536 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 34 ms | 8736 KB | Output is correct |
2 | Correct | 30 ms | 8992 KB | Output is correct |
3 | Correct | 31 ms | 9112 KB | Output is correct |
4 | Correct | 32 ms | 9480 KB | Output is correct |
5 | Correct | 33 ms | 9848 KB | Output is correct |
6 | Correct | 36 ms | 9856 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 998 ms | 5376 KB | Output is correct |
2 | Correct | 617 ms | 4728 KB | Output is correct |
3 | Correct | 1361 ms | 6012 KB | Output is correct |
4 | Correct | 949 ms | 6056 KB | Output is correct |
5 | Correct | 562 ms | 4600 KB | Output is correct |
6 | Correct | 597 ms | 4472 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 1536 KB | Output is correct |
2 | Correct | 63 ms | 1536 KB | Output is correct |
3 | Correct | 289 ms | 1536 KB | Output is correct |
4 | Correct | 924 ms | 1640 KB | Output is correct |
5 | Correct | 6 ms | 1536 KB | Output is correct |
6 | Correct | 5 ms | 1536 KB | Output is correct |
7 | Correct | 5 ms | 1536 KB | Output is correct |
8 | Correct | 34 ms | 8736 KB | Output is correct |
9 | Correct | 30 ms | 8992 KB | Output is correct |
10 | Correct | 31 ms | 9112 KB | Output is correct |
11 | Correct | 32 ms | 9480 KB | Output is correct |
12 | Correct | 33 ms | 9848 KB | Output is correct |
13 | Correct | 36 ms | 9856 KB | Output is correct |
14 | Correct | 998 ms | 5376 KB | Output is correct |
15 | Correct | 617 ms | 4728 KB | Output is correct |
16 | Correct | 1361 ms | 6012 KB | Output is correct |
17 | Correct | 949 ms | 6056 KB | Output is correct |
18 | Correct | 562 ms | 4600 KB | Output is correct |
19 | Correct | 597 ms | 4472 KB | Output is correct |
20 | Execution timed out | 5056 ms | 2944 KB | Time limit exceeded |
21 | Halted | 0 ms | 0 KB | - |