답안 #469242

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
469242 2021-08-31T08:35:28 Z amirmohammad_nezami 회문 (APIO14_palindrome) C++14
23 / 100
1000 ms 7544 KB
#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define PB push_back
#define ll long long
#define _sz(e) e.size()
#define pii pair <int , int>
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#pragma GCC target("sse4,avx,avx2")
#pragma GCC optimize("O3,unroll-loops")

const ll maxn = 1e5 + 8 , N = 200 + 8 , base = 301 , mod = 1e9 + 7 , INF = 1e18;

unordered_map <int , int> mp;

ll n , h[maxn] , hrev[maxn] , pbase[maxn];
string s;

void pre() {
    pbase[0] = 1;
    for (int i = 1; i < maxn; ++i) {
        pbase[i] = (pbase[i - 1] * base) % mod;
    } 
    for (int i = 1; i <= n; ++i) {
        h[i] = (h[i - 1] * base + s[i - 1]) % mod;
    }
    for (int i = n; i >= 1; --i) {
        hrev[i] = (hrev[i + 1] * base + s[i - 1]) % mod;
    }
}

int HASH(int l , int r) {
    return (h[r] - (h[l] * pbase[r - l] % mod) + mod) % mod;
}

int HASHrev(int l , int r) {
    return (hrev[l + 1] - (hrev[r + 1] * pbase[r - l] % mod) + mod) % mod;
}

bool palindrome(int l , int r) {
    int mid = (l + r) / 2;
    if((r - l) & 1) {
        if(r - l == 1) return 1;
        return (HASH(l , mid) == HASHrev(mid + 1 , r));
    }
    return (HASH(l , mid) == HASHrev(mid , r));
}

int main() {
    FAST;
    cin >> s; n = _sz(s);
    pre();

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j <= n; ++j) {
            if(!palindrome(i , j)) continue;
            // cout << i << ' ' << j << endl;
            mp[HASH(i , j)]++;
        }   
    }
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j <= n; ++j) {
            if(!palindrome(i , j)) continue;
            ans = max(ans , 1ll * mp[HASH(i , j)] * (j - i));
        }
    }
    cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1100 KB Output is correct
2 Correct 1 ms 1100 KB Output is correct
3 Correct 1 ms 1100 KB Output is correct
4 Correct 1 ms 1100 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 1 ms 1100 KB Output is correct
7 Correct 1 ms 1084 KB Output is correct
8 Correct 1 ms 1100 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 2 ms 1100 KB Output is correct
11 Correct 1 ms 1100 KB Output is correct
12 Correct 2 ms 1100 KB Output is correct
13 Correct 1 ms 1084 KB Output is correct
14 Correct 1 ms 1100 KB Output is correct
15 Correct 1 ms 1100 KB Output is correct
16 Correct 1 ms 1092 KB Output is correct
17 Correct 1 ms 1100 KB Output is correct
18 Correct 1 ms 1100 KB Output is correct
19 Correct 2 ms 1084 KB Output is correct
20 Correct 2 ms 1084 KB Output is correct
21 Correct 2 ms 1100 KB Output is correct
22 Correct 2 ms 1100 KB Output is correct
23 Correct 2 ms 1100 KB Output is correct
24 Correct 2 ms 1100 KB Output is correct
25 Correct 2 ms 1100 KB Output is correct
26 Correct 2 ms 1100 KB Output is correct
27 Correct 1 ms 1100 KB Output is correct
28 Correct 2 ms 1100 KB Output is correct
29 Correct 2 ms 1084 KB Output is correct
30 Correct 2 ms 1100 KB Output is correct
31 Correct 2 ms 1088 KB Output is correct
32 Correct 2 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 1100 KB Output is correct
2 Correct 22 ms 1136 KB Output is correct
3 Correct 52 ms 1100 KB Output is correct
4 Correct 15 ms 1140 KB Output is correct
5 Correct 55 ms 1100 KB Output is correct
6 Correct 50 ms 1144 KB Output is correct
7 Correct 17 ms 1164 KB Output is correct
8 Correct 31 ms 1140 KB Output is correct
9 Correct 15 ms 1100 KB Output is correct
10 Correct 14 ms 1100 KB Output is correct
11 Correct 18 ms 1100 KB Output is correct
12 Correct 14 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1086 ms 1612 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1079 ms 7544 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 4700 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -