Submission #894866

# Submission time Handle Problem Language Result Execution time Memory
894866 2023-12-29T06:42:19 Z vjudge1 Palinilap (COI16_palinilap) C++17
17 / 100
1000 ms 1380 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;

#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define russian setlocale(LC_ALL,"Russian_Russia.20866");
#define file freopen("condense2.in", "r", stdin), freopen("condense2.out", "w", stdout);
#define ll long long
#define ull unsigned long long
#define ld long double
#define pll pair<ll, ll>
#define pii pair<int, int>
#define pli pair<ll, int>
#define all(s) s.begin(), s.end()
#define pb push_back
#define ins insert
#define mp make_pair
#define sz(x) x.size()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define mem(x) memset(x, 0, sizeof(x))

const ll N = 1010;
const ll M = 1e9 + 7;
const ll block = 316;
const ll mod = 1e9 + 7;
const ll P = 263;
const ld pi = acos(-1);
const ll inf = 1e18;

ll add(ll a, ll b) {
    if(a + b < 0) return a + b + mod;
    if(a + b >= mod) return a + b - mod;
    return a + b;
}

ll sub(ll a, ll b) {
    return (a - b + mod) % mod;
}

ll mul(ll a, ll b) {
    return a * b % mod;
}

ll binpow(ll a, ll n) {
    ll res = 1;
    while(n) {
        if(n & 1) res = mul(res, a);
        a = mul(a, a);
        n >>= 1;
    }
    return res;
}

ll inv(ll x) {
    return binpow(x, mod - 2);
}
void solve() {
    string s;
    cin >> s;
    int n = (int)sz(s);
    ll ans = 0;
    string tmp;
    vector<int> d1(n, 0), d2(n, 0);
    for(int pos = 0; pos < n; pos++) {
        for(char x = 'a'; x <= 'z'; x++) {
            char prev = s[pos];
            s[pos] = x;
            int l = 0, r = -1;
            for (int i = 0; i < n; i++) {
                int k = i > r ? 1 : min(d1[l + r - i], r - i + 1);
                while(i + k < n && i - k >= 0 && s[i + k] == s[i - k]) k++;
                d1[i] = k;
                if(i + k - 1 > r) l = i - k + 1, r = i + k - 1;
            }
            l = 0, r = -1;
            for (int i = 0; i < n; i++) {
                int k = i > r ? 0 : min(d2[l + r - i + 1], r - i + 1);
                while (i + k < n && i - k - 1 >= 0 && s[i + k] == s[i - k - 1]) k++;
                d2[i] = k;
                if(i + k - 1 > r) l = i - k, r = i + k - 1;
            }
            ll cur = 0;
            for(int i = 0; i < n; i++) {
                cur += d1[i] + d2[i];
                d1[i] = 0;
                d2[i] = 0;
            }
            if(ans < cur) {
                ans = cur;
                //tmp = s;
            }
            s[pos] = char(prev);
        }
    }
    cout << ans << '\n';
    //cout << tmp << '\n';
}
signed main() {
    speed;
    //file;
    int test = 1;
    //cin >> test;
    while(test--) {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 3 ms 452 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 356 KB Output is correct
5 Correct 3 ms 356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1012 ms 356 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1036 ms 1380 KB Time limit exceeded
2 Halted 0 ms 0 KB -