Submission #716932

# Submission time Handle Problem Language Result Execution time Memory
716932 2023-03-31T12:23:12 Z pragmatist Palindromes (APIO14_palindrome) C++17
47 / 100
1000 ms 65664 KB
#include <bits/stdc++.h>   
#include <ext/pb_ds/assoc_container.hpp>                  
  
#define ll long long 
#define pb push_back
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(v) (int)v.size()
#define x first
#define y second
#define nl "\n"
  
using namespace std;
using namespace __gnu_pbds;
  
const int N = (int)3e5 + 7;
const int M = (int)2e6 + 5e5 + 7;
const ll MOD = (ll)998244353;                    
const int inf = (int)1e9 + 7;
const int B = (int)390;
const ll INF = (ll)1e18 + 7;
  
pair<int, int> dir[] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
 
bool bit(int mask, int i) {
    return (mask >> i & 1);
}
  
int sum(int x, int y) {
    x += y;
    if(x >= MOD) x -= MOD;
    return x;
}
  
int sub(int x, int y) {
	x -= y;
	if(x < 0) x += MOD;
	return x;
}

int mult(int x, int y) {
    return 1ll * x * y % MOD;
}


string s;
int n, p[N], h[N];

int get(int l, int r) {
	return mult(sub(h[r], h[l - 1]), p[n - r + 1]);
}                       

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

void solve() {
	cin >> s;
	n = sz(s);
	s = '#' + s;
	for(int i = 1; i <= n; ++i) {
		h[i] = sum(h[i - 1], mult(s[i] - 'a' + 1, p[i]));
	}
	
	gp_hash_table<int, int, custom_hash> cnt[n + 1];
	for(int i = 1; i <= n; ++i) {
		int l = i + 1, r = i - 1;
		while(s[l - 1] == s[r + 1]) {
			l--;
			r++;
			if(l < 1 || r > n) break;
			cnt[r - l + 1][get(l, r)]++;
		}
		l = i + 1, r = i;
		while(s[l - 1] == s[r + 1]) {
			l--;
			r++;
			if(l < 1 || r > n) break;
			cnt[r - l + 1][get(l, r)]++;
		}
	}
	int ans = 0;
	for(int i = 1; i <= n; ++i) {
		for(auto [x, y] : cnt[i]) {
			ans = max(ans, y * i);
		}
	}
	cout << ans << nl;
}       
 
  
signed main() {                   
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    //freopen("in.txt", "r", stdin);
    p[0] = 1;
    for(int i = 1; i <= 1e5; ++i) {
    	p[i] = mult(p[i - 1], 31);
    }
    //freopen("palindrome.in", "r", stdin);
    //freopen("palindrome.out", "w", stdout);    
    int test = 1;                       
    //cin >> test;
    for(int i = 1; i <= test; ++i) {
        //cout << "Case " << i << ":\n";
        solve();
    }
    return 0;
}                   
/*
possible causes of error :
* array  bounds
* int overflow
* special case (n == 1?)
* haven't clean something
* wrong N | M | inf | INF | MOD

* try to write brute force to find test
* don't waste time
* don't write bullshit
* solution is easy
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 732 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 728 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 1 ms 732 KB Output is correct
11 Correct 1 ms 724 KB Output is correct
12 Correct 2 ms 724 KB Output is correct
13 Correct 1 ms 728 KB Output is correct
14 Correct 1 ms 732 KB Output is correct
15 Correct 1 ms 608 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 1 ms 724 KB Output is correct
18 Correct 1 ms 728 KB Output is correct
19 Correct 1 ms 852 KB Output is correct
20 Correct 1 ms 724 KB Output is correct
21 Correct 1 ms 724 KB Output is correct
22 Correct 1 ms 724 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 1 ms 724 KB Output is correct
25 Correct 1 ms 724 KB Output is correct
26 Correct 1 ms 724 KB Output is correct
27 Correct 1 ms 724 KB Output is correct
28 Correct 1 ms 728 KB Output is correct
29 Correct 1 ms 728 KB Output is correct
30 Correct 1 ms 724 KB Output is correct
31 Correct 1 ms 724 KB Output is correct
32 Correct 1 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 852 KB Output is correct
2 Correct 4 ms 980 KB Output is correct
3 Correct 10 ms 852 KB Output is correct
4 Correct 3 ms 852 KB Output is correct
5 Correct 10 ms 852 KB Output is correct
6 Correct 12 ms 852 KB Output is correct
7 Correct 2 ms 856 KB Output is correct
8 Correct 6 ms 852 KB Output is correct
9 Correct 2 ms 856 KB Output is correct
10 Correct 2 ms 856 KB Output is correct
11 Correct 2 ms 852 KB Output is correct
12 Correct 1 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 452 ms 2876 KB Output is correct
2 Correct 283 ms 3144 KB Output is correct
3 Correct 953 ms 2880 KB Output is correct
4 Correct 714 ms 2876 KB Output is correct
5 Correct 5 ms 3028 KB Output is correct
6 Correct 28 ms 3040 KB Output is correct
7 Correct 98 ms 3144 KB Output is correct
8 Correct 3 ms 2900 KB Output is correct
9 Correct 3 ms 2912 KB Output is correct
10 Correct 5 ms 3156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1058 ms 22352 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1070 ms 65664 KB Time limit exceeded
2 Halted 0 ms 0 KB -