# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
464540 | prvocislo | Difference (POI11_roz) | C++17 | 151 ms | 65540 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
int ans = 0;
void solve(const vector<int>& v) // v je indexovane od 1
{
int last_minus_one = -1;
vector<int> pf(v.size(), 0), pf_min(v.size(), 0); // prefixove sucty, najmensi prefix doteraz
for (int i = 1; i < v.size(); i++)
{
pf[i] = pf[i - 1] + v[i];
pf_min[i] = min(pf_min[i - 1], pf[i]);
}
for (int i = 1; i < v.size(); i++)
{
if (v[i] == -1) last_minus_one = i;
if (last_minus_one != -1) ans = max(ans, pf[i] - pf_min[last_minus_one - 1]);
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
string s;
cin >> s;
vector<vector<vector<int> > > v(26, vector<vector<int> >(26, { 0 }));
for (int i = 0; i < n; i++)
{
for (int j = 0; j < 26; j++) if (j != s[i] - 'a')
{
v[s[i] - 'a'][j].push_back(1);
v[j][s[i] - 'a'].push_back(-1);
}
}
for (int i = 0; i < 26; i++) for (int j = 0; j < 26; j++) if (j != i)
solve(v[i][j]);
cout << ans << "\n";
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |