Submission #268139

# Submission time Handle Problem Language Result Execution time Memory
268139 2020-08-16T09:21:12 Z kartel Palinilap (COI16_palinilap) C++14
54 / 100
1000 ms 1640 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("no-stack-protector")
#define F first
#define S second
#define pb push_back
#define N +300500
#define M ll(1e9 + 7)
#define sz(x) (int)x.size()
#define re return
#define oo ll(1e9)
#define el '\n'
#define Max_A int(1e9)
//#define el endl
#define pii pair <int, int>
#define piii pair <int, pair <int, int> >
#define psi pair <string, int>
#define err ld(1e-9)
#define Max_S int(3e6)
#define last(x) x.back()
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define arr_all(x, n) (x + 1), (x + 1 + n)
#define vi vector<int>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree <int, null_type, less_equal <int> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;

ll ans, cur;
string s;
int i, n;
char c;

ll f(string s)
{
    cur = 0;
    vi d1(n);

    int l = 0, r = -1;

    for (int j = 0; j < n; j++)
    {
       int k = ((j > r) ? 1 : min(d1[l + r - j],
                                   r - j + 1));

       while (j + k < n && j - k >= 0 && s[j + k] == s[j - k]) k++;

       d1[j] = k;

       if (j + k - 1 > r)
         {
             l = j - k + 1;
             r = j + k - 1;
         }
    }

    vi d2(n);

    l = 0;
    r = -1;

    for (int j = 0; j < n; j++)
    {
       int k = ((j > r) ? 0 : min(d2[l + r - j + 1],
                                   r - j + 1));

       while (j + k < n && j - k - 1 >= 0 && s[j + k] == s[j - k - 1]) k++;

       d2[j] = k;

       if (j + k - 1 > r)
         {
             l = j - k;
             r = j + k - 1;
         }
    }

    for (int j = 0; j < n; j++)
        cur += d1[j] + d2[j];
    return cur;
}

int main()
{
//    srand(time(0));
    cout.precision(3);
    cout << fixed;
    ios_base::sync_with_stdio(0);
    iostream::sync_with_stdio(0);
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

//    in("input.txt");
//    out("output.txt");

    cin >> s;

    n = sz(s);

    ans = f(s);

    for (i = 0; i < n; i++)
    {
        char old_c = s[i];

        if (i < n - 1)
        {
            s[i] = s[i + 1];

            ans = max(ans, f(s));
        }
        if (i > 0)
        {
            s[i] = s[i - 1];

            ans = max(ans, f(s));
        }

        s[i] = s[n - i - 1];

        ans = max(ans, f(s));

        s[i] = old_c;
    }

    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 288 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 866 ms 428 KB Output is correct
2 Correct 838 ms 428 KB Output is correct
3 Correct 648 ms 436 KB Output is correct
4 Correct 278 ms 408 KB Output is correct
5 Correct 637 ms 420 KB Output is correct
6 Correct 834 ms 504 KB Output is correct
7 Correct 590 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1088 ms 1640 KB Time limit exceeded
2 Halted 0 ms 0 KB -