답안 #47330

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
47330 2018-05-01T04:52:56 Z Talant 회문 (APIO14_palindrome) C++17
23 / 100
170 ms 41368 KB
#include <bits/stdc++.h>

#define mk make_pair
#define sc second
#define fr first
#define pb emplace_back
#define all(s) s.begin(), s.end()
#define sz(s) ( (int)s.size() )
#define int long long

using namespace std;

const int inf = (int)1e18 + 7;
const int N = (int)2e5 + 7;

int p = 997;
int dp[1002][1002];
int hs[N],pw[N];
int n,ans;

string a;
unordered_map<int,int> u;

void f (int l,int r) {
      int lst= 0;
      if (l > 0)
            lst = hs[l - 1];

      int o = hs[r] - lst;

      o *= pw[n - l];

      u[o] ++;
      ans = max(ans,u[o] * (r - l + 1));
}
main () {
      pw[0] = 1;
      for (int i = 1; i <= 1010; i ++)
            pw[i] = pw[i - 1] * p;

      cin >> a;

      n = a.size();

      hs[0] = (int)(a[0] - 'a' + 1);

      for (int i = 1; i < n; i ++)
            hs[i] = hs[i - 1] + (pw[i] * (int)(a[i] - 'a' + 1));

      for (int i = 0; i < n; i ++) {
            for (int j = i; j >= 0; j --) {
                  if (i - j <= 1) {
                        if (a[i] == a[j]) {
                              dp[j][i] = 1;
                              f(j,i);
                        }
                  }
                  else if (dp[j + 1][i - 1] && a[j] == a[i]){
                        dp[j][i] = 1;
                        f(j,i);
                  }
            }
      }
      cout << ans << endl;
}

Compilation message

palindrome.cpp:36:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 428 KB Output is correct
3 Correct 2 ms 540 KB Output is correct
4 Correct 1 ms 540 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 2 ms 540 KB Output is correct
7 Correct 2 ms 540 KB Output is correct
8 Correct 2 ms 540 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 656 KB Output is correct
11 Correct 13 ms 656 KB Output is correct
12 Correct 2 ms 656 KB Output is correct
13 Correct 2 ms 664 KB Output is correct
14 Correct 2 ms 668 KB Output is correct
15 Correct 2 ms 672 KB Output is correct
16 Correct 2 ms 672 KB Output is correct
17 Correct 2 ms 672 KB Output is correct
18 Correct 2 ms 672 KB Output is correct
19 Correct 2 ms 988 KB Output is correct
20 Correct 2 ms 992 KB Output is correct
21 Correct 2 ms 996 KB Output is correct
22 Correct 2 ms 1000 KB Output is correct
23 Correct 3 ms 1004 KB Output is correct
24 Correct 2 ms 1052 KB Output is correct
25 Correct 2 ms 1184 KB Output is correct
26 Correct 2 ms 1184 KB Output is correct
27 Correct 2 ms 1184 KB Output is correct
28 Correct 2 ms 1184 KB Output is correct
29 Correct 2 ms 1184 KB Output is correct
30 Correct 2 ms 1184 KB Output is correct
31 Correct 2 ms 1184 KB Output is correct
32 Correct 2 ms 1184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 7624 KB Output is correct
2 Correct 13 ms 7624 KB Output is correct
3 Correct 65 ms 7632 KB Output is correct
4 Correct 8 ms 7632 KB Output is correct
5 Correct 36 ms 7636 KB Output is correct
6 Correct 33 ms 7636 KB Output is correct
7 Correct 9 ms 7636 KB Output is correct
8 Correct 22 ms 7636 KB Output is correct
9 Correct 10 ms 7636 KB Output is correct
10 Correct 6 ms 7636 KB Output is correct
11 Correct 6 ms 7636 KB Output is correct
12 Correct 8 ms 7636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 36 ms 14952 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 34 ms 16804 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 170 ms 41368 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -