답안 #110092

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
110092 2019-05-09T12:31:31 Z TAISA_ 회문 (APIO14_palindrome) C++14
0 / 100
1000 ms 1288 KB
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 40) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T>
bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for(int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
    for(auto& e : t) {
        fill_v(e, v);
    }
};
struct RH {
    string s;
    int n;
    vector<ll> h1, h2, p1, p2;
    ll m1 = 1000000007LL, b1 = 1007LL, m2 = 1000000009LL, b2 = 1009LL;
    RH(string t) {
        s = t;
        n = t.length();
        h1.resize(n + 10);
        h2.resize(n + 10);
        p1.resize(n + 10, 1);
        p2.resize(n + 10, 1);
        for(int i = 0; i < n; i++) {
            h1[i + 1] = (h1[i] + s[i]) * b1 % m1;
            h2[i + 1] = (h2[i] + s[i]) * b2 % m2;
            p1[i + 1] = p1[i] * b1 % m1;
            p2[i + 1] = p2[i] * b2 % m2;
        }
    }
    P get(int l, int r) {  //[l,r)
        ll t1 = (h1[r] - h1[l] * p1[r - l] % m1 + m1) % m1;
        ll t2 = (h2[r] - h2[l] * p2[r - l] % m2 + m2) % m2;
        return P(t1, t2);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.length();
    if(n > 10000) {
        return 0;
    }
    RH rh(s);
    map<P, ll> mp;
    for(int i = 0; i < n; i++) {
        for(int j = i; j < n; j++) {
            if(i == j) {
                mp[rh.get(i, j + 1)]++;
            } else {
                if((j - i) % 2) {
                    if(rh.get(i, i + (j - i + 1) / 2) ==
                       rh.get(i + (j - i + 1) / 2, j + 1)) {
                        mp[rh.get(i, j + 1)] += j - i + 1;
                    }
                } else {
                    if(rh.get(i, i + (j - i) / 2) ==
                       rh.get(i + (j - i) / 2 + 1, j + 1)) {
                        mp[rh.get(i, j + 1)] += j - i + 1;
                    }
                }
            }
        }
    }
    ll ans = 0;
    for(auto itr = mp.begin(); itr != mp.end(); itr++) {
        chmax(ans, itr->second);
    }
    cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Incorrect 3 ms 384 KB Output isn't correct
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 74 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1057 ms 1280 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 1288 KB Output isn't correct
2 Halted 0 ms 0 KB -