답안 #676327

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
676327 2022-12-30T10:44:30 Z vuavisao 회문 (APIO14_palindrome) C++14
23 / 100
15 ms 1244 KB
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define ll long long
using namespace std;

template<typename Lhs, typename Rhs> inline bool Max_self(Lhs &a, Rhs b) { if(b > a) { a = b; return true; } return false; }
template<typename Lhs, typename Rhs> inline bool Min_self(Lhs &a, Rhs b) { if(b < a) { a = b; return true; } return false; }

const int N = 3e5 + 10;

int n;
string s;

namespace sub123 {
    bool check() {
        return n <= 1000;
    }

    const int BASE = 128;
    const int MOD = 1e9 + 7;

    int p[N], h[N], h_rev[N];
    int res;

    int get_hash(int l, int r, int* h) {
        return (h[r] - 1ll * h[l - 1] * p[r - l + 1] % MOD + MOD) % MOD;
    }


    void solve() {
        p[0] = 1;
        for(int i = 1; i <= n; ++ i) {
            p[i] = 1ll * p[i - 1] * BASE % MOD;
            h[i] = (1ll * h[i - 1] * BASE + s[i]) % MOD;
            h_rev[i] = (1ll * h_rev[i - 1] * BASE + s[n - i + 1]) % MOD;
        }
        for(int len = 1; len <= n; ++ len) {
            unordered_map<int, int> mpp;
            auto palin = [&] (int l, int r) -> bool {
                return get_hash(l, r, h) == get_hash(n - r + 1, n - l + 1, h_rev);
            };
            for(int i = 1; i <= n - len + 1; ++ i) {
                if(palin(i, i + len - 1)) {
                    int hash = get_hash(i, i + len - 1, h);
                    ++ mpp[hash];
                    Max_self(res, mpp[hash] * len);
                }
            }
        }
        cout << res;
    }
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if (fopen("APIO14_palindrome.inp", "r")) {
        freopen("APIO14_palindrome.inp", "r", stdin);
        freopen("APIO14_palindrome.out", "w", stdout);
    }
    cin >> s; n = (int) s.size(); s = ' ' + s;
    if(sub123::check()) {
        sub123::solve();
        return 0;
    }
    return 0;
}

/// Code by vuavisao

Compilation message

palindrome.cpp: In function 'int32_t main()':
palindrome.cpp:60:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |         freopen("APIO14_palindrome.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
palindrome.cpp:61:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |         freopen("APIO14_palindrome.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 324 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 0 ms 328 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 324 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 340 KB Output is correct
2 Correct 7 ms 340 KB Output is correct
3 Correct 15 ms 340 KB Output is correct
4 Correct 5 ms 340 KB Output is correct
5 Correct 15 ms 340 KB Output is correct
6 Correct 15 ms 340 KB Output is correct
7 Correct 5 ms 340 KB Output is correct
8 Correct 9 ms 332 KB Output is correct
9 Correct 4 ms 340 KB Output is correct
10 Correct 4 ms 340 KB Output is correct
11 Correct 4 ms 328 KB Output is correct
12 Correct 5 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1244 KB Output isn't correct
2 Halted 0 ms 0 KB -