Submission #955473

# Submission time Handle Problem Language Result Execution time Memory
955473 2024-03-30T14:04:22 Z hoanganh_siuuuuuuuu Palindromes (APIO14_palindrome) C++17
47 / 100
1000 ms 6672 KB
#include <bits/stdc++.h>
#define int long long
#define f(i, a, b) for(int i = a; i <= b; i++)
#define fr(i, a, b) for(int i = a; i >= b; i--)
#define pii pair <int, int>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define in insert
#define vvec vector<vector<int>>
#define fast ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace std;

const int N = 3e5 + 5;
const int mod = 1e9 + 7;
const int base = 31;
int n, Hash[N], Pow[N];
unordered_map <int, int> mp;
string s;

int get(int i, int j)
{
    return (Hash[j] - Hash[i - 1] * Pow[j - i + 1] + mod * mod) % mod;
}

void sub2()
{
    int res = 0;
    f(i, 1, n)
    {
        int t = 0;
        while(i - t >= 1 && i + t <= n && s[i - t] == s[i + t])
        {
            int z = ++mp[get(i - t, i + t)];
            // cout << get(i - t, i + t) << "\n";
            //cout << i << " " << z << " " << (2 * t + 1) << "\n";
            res = max(res, (2 * t + 1) * z);
            t++;
        }

        t = 0; int j = i + 1;
        while(i - t >= 1 && j + t <= n && s[i - t] == s[j + t])
        {
            int z = ++mp[get(i - t, j + t)];
            //cout << get(i - t, j + t) << "\n";
            //cout << i << " " << z << " " << (2 * t + 2) << "\n";
            res = max(res, (2 * t + 2) * z);
            t++;
        }
    }
    cout << res;
}

signed main()
{
    fast;
    if(fopen("palindrome.in", "r"))
    {
        freopen("palindrome.in", "r", stdin);
        freopen("palindrome.out", "w", stdout);
    }
    cin >> s;
    n = s.size(); s = '!' + s;
    Pow[0] = 1;
    f(i, 1, n)
    {
        //a[i] = s[i] - 'a';
        Hash[i] = (Hash[i - 1] * base + (s[i] - 'a' + 1)) % mod;
        Pow[i] = (Pow[i - 1] * base) % mod;
    }
    sub2();
    //int l = 0,
}

Compilation message

palindrome.cpp: In function 'int main()':
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("palindrome.in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
palindrome.cpp:62:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |         freopen("palindrome.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 464 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 424 KB Output is correct
29 Correct 0 ms 612 KB Output is correct
30 Correct 1 ms 476 KB Output is correct
31 Correct 0 ms 360 KB Output is correct
32 Correct 1 ms 360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 548 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 7 ms 360 KB Output is correct
4 Correct 2 ms 612 KB Output is correct
5 Correct 7 ms 360 KB Output is correct
6 Correct 7 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 4 ms 348 KB Output is correct
9 Correct 1 ms 352 KB Output is correct
10 Correct 0 ms 412 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 452 ms 1108 KB Output is correct
2 Correct 214 ms 908 KB Output is correct
3 Correct 849 ms 900 KB Output is correct
4 Correct 603 ms 1364 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 16 ms 860 KB Output is correct
7 Correct 64 ms 772 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1028 ms 4672 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1059 ms 6672 KB Time limit exceeded
2 Halted 0 ms 0 KB -