답안 #223421

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
223421 2020-04-15T08:59:49 Z dantoh000 Lampice (COCI19_lampice) C++14
25 / 110
30 ms 3960 KB
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> adjlist[50005];
int main(){
    scanf("%d",&n);
    string s;
    cin >> s;
    for (int i = 0; i < n-1; i++){
        int a,b;
        scanf("%d%d",&a,&b);
        adjlist[a].push_back(b);
    }

    ///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 ;
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++){
        ans = max(ans,max(2*d1[i]-1,2*d2[i]));
    }
    printf("%d\n",ans);

}

Compilation message

lampice.cpp: In function 'int main()':
lampice.cpp:6:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
lampice.cpp:11:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&a,&b);
         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 1536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 3192 KB Output is correct
2 Correct 23 ms 3712 KB Output is correct
3 Correct 25 ms 3832 KB Output is correct
4 Correct 23 ms 3960 KB Output is correct
5 Correct 24 ms 3840 KB Output is correct
6 Correct 24 ms 3840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 30 ms 3448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 1536 KB Output isn't correct
2 Halted 0 ms 0 KB -