# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
224002 | cheeheng | Lampice (COCI19_lampice) | C++14 | 6 ms | 1024 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
char str[50005];
char S[50005];
int P[100005];
int L[100005]; // length of the palindrome for each center point in S (initially all 0s)
int main(){
int N;
scanf("%d", &N);
scanf(" %s", str);
// https://www.geeksforgeeks.org/manachers-algorithm-linear-time-longest-palindromic-substring-part-4/
// https://en.wikipedia.org/wiki/Longest_palindromic_substring
S[0] = '|';
memset(P, 0, sizeof(P));
for(int i = 0; i < N; i ++){
S[i*2+1] = str[i];
S[i*2+2] = '|';
}
int c = 0, r = 0; // first element in S ('|') has been processed
int m = 0, n = 0; // walking indices to check whether 2 elements are the same
for(int i = 0; i <= 2*N; i ++){
if(i > r){
P[i] = 0;
m = i-1;
n = i+1;
}else{
int i2 = c*2-i; // left boundary
if(P[i2] < r-i-1){
P[i] = P[i2];
m = -1; // bypass the while loop because one of the cases has been met
}else{
P[i] = r-i;
n = r+1; // right boundary to check
m = i*2-n; // left boundary to check
}
}
while(m >= 0 && n < 2*N+1 && S[m] == S[n]){
P[i] ++;
m --; // adjust left boundary by 1
n ++; // adjust right boundary by 1
}
if(i+P[i] > r){
c = i;
r = i+P[i];
}
}
int ans = 0;
for(int i = 0; i <= 2*N; i ++){
ans = max(ans, P[i]);
}
printf("%d", ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |