제출 #998535

#제출 시각아이디문제언어결과실행 시간메모리
998535Ibrohim0704회문 (APIO14_palindrome)C++14
컴파일 에러
0 ms0 KiB
def manacher(s): """Manacher's Algorithm to find all palindromic substrings in linear time.""" s = '#' + '#'.join(s) + '#' n = len(s) p = [0] * n c = 0 r = 0 for i in range(n): mirror = 2 * c - i if i < r: p[i] = min(r - i, p[mirror]) while i + p[i] + 1 < n and i - p[i] - 1 >= 0 and s[i + p[i] + 1] == s[i - p[i] - 1]: p[i] += 1 if i + p[i] > r: c = i r = i + p[i] return s, p def find_max_palindrome_occurrence_value(s): original_s = s s, p = manacher(s) n = len(p) # To store the count of each palindrome palindrome_count = {} for i in range(n): length = p[i] if length > 0: start = (i - length) // 2 for l in range(1, length + 1): pal_sub = original_s[start:start + l] if pal_sub in palindrome_count: palindrome_count[pal_sub] += 1 else: palindrome_count[pal_sub] = 1 start -= 1 max_occurrence_value = 0 for pal, count in palindrome_count.items(): occurrence_value = len(pal) * count if occurrence_value > max_occurrence_value: max_occurrence_value = occurrence_value return max_occurrence_value # Read input from file with open('palindrome.in', 'r') as file: s = file.read().strip() # Calculate the maximum occurrence value of palindromic substrings result = find_max_palindrome_occurrence_value(s) # Write output to file with open('palindrome.out', 'w') as file: file.write(str(result) + '\n')

컴파일 시 표준 에러 (stderr) 메시지

palindrome.cpp:24:7: error: invalid preprocessing directive #To
   24 |     # To store the count of each palindrome
      |       ^~
palindrome.cpp:47:3: error: invalid preprocessing directive #Read
   47 | # Read input from file
      |   ^~~~
palindrome.cpp:48:11: warning: character constant too long for its type
   48 | with open('palindrome.in', 'r') as file:
      |           ^~~~~~~~~~~~~~~
palindrome.cpp:51:3: error: invalid preprocessing directive #Calculate
   51 | # Calculate the maximum occurrence value of palindromic substrings
      |   ^~~~~~~~~
palindrome.cpp:54:3: error: invalid preprocessing directive #Write
   54 | # Write output to file
      |   ^~~~~
palindrome.cpp:55:11: warning: character constant too long for its type
   55 | with open('palindrome.out', 'w') as file:
      |           ^~~~~~~~~~~~~~~~
palindrome.cpp:1:1: error: 'def' does not name a type
    1 | def manacher(s):
      | ^~~
palindrome.cpp:27:5: error: expected unqualified-id before 'for'
   27 |     for i in range(n):
      |     ^~~