Untitled
unknown
plain_text
a year ago
2.6 kB
5
Indexable
#include <bits/stdc++.h> using namespace std; #define INF 100000000 #define ll long long #define file \ freopen("matrix.in", "r", stdin); // freopen("output.txt", "w", stdout) #define OJudge(in,out) \ freopen(in, "r", stdin);\ freopen(out, "w", stdout) #define FIn \ cin.tie(0); \ cout.tie(0); \ ios_base::sync_with_stdio(false) #define endl '\n' #define all(x) x.begin(), x.end() const string IN = "input.txt"; const string OUT = "output.txt"; typedef long double T; typedef complex<T> pt; //#define x real() //#define y imag() //const ll p = 998244353; int tc; //const T pi = 3.1415926535897; string alpha = "abcdefghijklmnopqrstuvwxyz"; typedef pair<int,int> pii; struct cmp { bool operator()(const pair<pii, int> &p1, const pair<pii,int> &p2) const { return p1.first < p2.first; } }; int n, f, m, P, x, z, y; const int N = 1e6 + 5; int arr[N]; ll val_for[N], val_back[N]; int pi_for[N], pi_rev[N]; //string str; void brute() {} void prefix_function_for(string &str) { for (int i = 1; i < n; i++) { int j = pi_for[i - 1]; while (j > 0 && str[i] != str[j]) j = pi_for[j - 1]; if (str[i] == str[j]) j++; pi_for[i] = j; if (pi_for[i] != 0) val_for[i] = 1LL * pi_for[i] * x - 1LL * i * z - z; else val_for[i] = 0; } } void prefix_function_back(string &str) { for (int i = 1; i < n; i++) { int j = pi_rev[i - 1]; while (j > 0 && str[i] != str[j]) j = pi_rev[j - 1]; if (str[i] == str[j]) j++; pi_rev[i] = j; if (pi_rev[i] != 0) val_back[n - i - 1] = max(val_back[n - i], 1LL * pi_rev[i] * y + 1LL * (n - i - 1) * z); else val_back[n - i - 1] = val_back[n - i]; } } void pre(); void solve(int tc) { cin >> n >> x >> y >> z; string str; cin >> str; prefix_function_for(str); reverse(all(str)); prefix_function_back(str); ll maxm = 0; for (int i = 1; i < n - 1; i++) { if (val_for[i] != 0 && val_back[i + 1] != 0) maxm = max(maxm, val_for[i] + val_back[i + 1]); } cout << maxm; } int main() { FIn; #ifndef ONLINE_JUDGE OJudge(IN.c_str(),OUT.c_str()); #endif // file; pre(); tc = 1; // cin >> tc; for(int i = 1; i <= tc; i++) { // cout << "Case #" << i <<": "; solve(i); } } void pre() {}
Editor is loading...
Leave a Comment