Submission #1106171

# Submission time Handle Problem Language Result Execution time Memory
1106171 2024-10-29T13:02:12 Z icebear Palindromes (APIO14_palindrome) C++17
47 / 100
1000 ms 4272 KB
// ~~ icebear ~~
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;

#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORR(i,a,b) for(int i=(a); i>=(b); --i)
#define rep(i, n) for(int i=0; i<(n); ++i)
#define red(i, n) for(int i=(n)-1; i>=0; --i)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define task "icebearat"

const int MOD = 1e9 + 7;
const int inf = 1e9 + 27092008;
const ll LLinf = 1e18 + 27092008;
const int base = 311;
const int N = 3e5 + 5;
int n, Hash[N], Pow[N], suffHash[N];
string s;
unordered_map<int, int> cnt;

int getHash(int l, int r) {
    return (Hash[r] - 1ll * Hash[l - 1] * Pow[r - l + 1] % MOD + MOD) % MOD;
}

int getSuff(int l, int r) {
    return (suffHash[l] - 1ll * suffHash[r + 1] * Pow[r - l + 1] % MOD + MOD) % MOD;
}

void solve() {
    cin >> s;
    n = (int)s.size();
    s = " " + s;

    Pow[0] = 1;
    FOR(i, 1, n) {
        Hash[i] = (1ll * Hash[i - 1] * base + s[i]) % MOD;
        Pow[i] = 1ll * Pow[i - 1] * base % MOD;
    }
    FORR(i, n, 1) suffHash[i] = (1ll * suffHash[i + 1] * base + s[i]) % MOD;

    int res = 0;
    FOR(len, 1, n) {
        cnt.clear();
        int mx = 0;
        FOR(i, 1, n - len + 1) 
            if (getHash(i, i + len - 1) == getSuff(i, i + len - 1))
                mx = max(mx, ++cnt[getHash(i, i + len - 1)]);
        res = max(res, mx * len);
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    int tc = 1;
//     cin >> tc;
    while(tc--) solve();
    return 0;
}

Compilation message

palindrome.cpp: In function 'int main()':
palindrome.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
palindrome.cpp:66:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 2 ms 2384 KB Output is correct
17 Correct 1 ms 2384 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 1 ms 2384 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 1 ms 2384 KB Output is correct
22 Correct 1 ms 2384 KB Output is correct
23 Correct 1 ms 2384 KB Output is correct
24 Correct 1 ms 2384 KB Output is correct
25 Correct 1 ms 2384 KB Output is correct
26 Correct 1 ms 2384 KB Output is correct
27 Correct 1 ms 2384 KB Output is correct
28 Correct 1 ms 2384 KB Output is correct
29 Correct 1 ms 2384 KB Output is correct
30 Correct 1 ms 2384 KB Output is correct
31 Correct 1 ms 2384 KB Output is correct
32 Correct 1 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2552 KB Output is correct
2 Correct 5 ms 2384 KB Output is correct
3 Correct 5 ms 2384 KB Output is correct
4 Correct 4 ms 2384 KB Output is correct
5 Correct 5 ms 2536 KB Output is correct
6 Correct 5 ms 2552 KB Output is correct
7 Correct 4 ms 2384 KB Output is correct
8 Correct 5 ms 2384 KB Output is correct
9 Correct 4 ms 2384 KB Output is correct
10 Correct 4 ms 2384 KB Output is correct
11 Correct 4 ms 2384 KB Output is correct
12 Correct 4 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 357 ms 2384 KB Output is correct
2 Correct 328 ms 2640 KB Output is correct
3 Correct 394 ms 2640 KB Output is correct
4 Correct 373 ms 2640 KB Output is correct
5 Correct 307 ms 2640 KB Output is correct
6 Correct 313 ms 2888 KB Output is correct
7 Correct 314 ms 2812 KB Output is correct
8 Correct 301 ms 2640 KB Output is correct
9 Correct 302 ms 2640 KB Output is correct
10 Correct 306 ms 2640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1058 ms 3316 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1065 ms 4272 KB Time limit exceeded
2 Halted 0 ms 0 KB -