답안 #984990

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
984990 2024-05-17T09:05:08 Z vjudge1 Lampice (COCI19_lampice) C++17
25 / 110
1 ms 860 KB
#include <bits/stdc++.h>

using namespace std;

#define TRACE(x) cerr << #x << " " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<

typedef long long llint;

using namespace std;

const int MAXN = 5e4 + 10;

char S[MAXN], T[2 * MAXN];

int n, t_len;
int P[2*MAXN];

inline void preprocess() {
  T[t_len++] = '!';
  for (int i = 0; i < n; ++i) {
    T[t_len++] = '#';
    T[t_len++] = S[i];
  }
  T[t_len++] = '#';
  T[t_len++] = '@';
}

int main(void) {
  scanf("%d", &n);
  scanf("%s", S);

  preprocess();

  int mid = 0, hi = 0, sol = 0;
  for (int i = 1; i < t_len - 1; ++i) {
      int _i = mid - (i - mid);
      if (hi > i)
          P[i] = min(hi - i, P[_i]);

      while (T[i + P[i] + 1] == T[i - P[i] - 1])
          ++P[i];

      if (i + P[i] > hi) {
          mid = i;
          hi = i + P[i];
      }
      sol = max(sol, P[i]);
  }

  printf("%d\n", sol);
  return 0;
}

Compilation message

lampice.cpp: In function 'int main()':
lampice.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
lampice.cpp:33:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |   scanf("%s", S);
      |   ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -