# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
885123 | catlover | Difference (POI11_roz) | C++14 | 588 ms | 36876 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 <bits/stdc++.h>
#define file(task) if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); }
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
#define pb push_back
#define SZ(X) (int)((X).size())
using namespace std;
const int maxN = 1e6;
int N;
string s;
vector<int> id[maxN+5];
void read_input()
{
cin >> N >> s;
}
void solve()
{
s = ' ' + s;
FOR(i, 1, N) id[s[i] - 'a'].pb(i);
int res = 0;
FOR(x, 0, 25)
{
FOR(y, 0, 25)
{
if(SZ(id[x]) * SZ(id[y]) == 0) continue;
if(x == y) continue;
vector<int> d {0};
int j = 0;
for(int i : id[x])
{
while(j < SZ(id[y]) && id[y][j] < i)
{
++j;
d.pb(-1);
}
d.pb(1);
}
while(j < SZ(id[y]))
{
++j;
d.pb(-1);
}
int last = 0, mn = 1e9;
vector<int> f(SZ(d), 0);
FOR(i, 1, SZ(d) - 1)
{
f[i] = f[i - 1] + d[i];
if(i > 1 && d[i] != d[i - 1])
{
FOR(j, last, i - 2) mn = min(mn, f[j]);
last = i - 1;
}
res = max(res, f[i] - mn);
}
}
}
cout << res;
}
int main()
{
cin.tie(0)->sync_with_stdio(0);
file("SSDIFF");
read_input();
solve();
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... |