# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
140853 | shafinalam | Difference (POI11_roz) | C++14 | 665 ms | 17164 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>
using namespace std;
#define ff first
#define ss second
const int mxn = 1e6+5;
typedef pair<int,int>pii;
#define input freopen("in.txt","r",stdin)
#define output freopen("out.txt","w",stdout)
#define all(v) v.begin(), v.end()
vector<pii>arr[30];
pii tmp[mxn];
int main()
{
//input;
//output;
int n;
scanf("%d", &n);
char ch;
for(int i = 0; i < n; i++)
{
scanf(" %c", &ch);
arr[ch-'a'].push_back(make_pair(i, ch-'a'));
}
int ans = -1;
for(int i = 0; i < 26; i++)
{
for(int r = 0; r < 26; r++)
{
if(i==r) continue;
merge(all(arr[i]), all(arr[r]), tmp);
int k = arr[i].size()+arr[r].size();
int sum = 0, best = -(1<<30);
for(int j = 0; j < k; j++)
{
if(tmp[j].ss==i)
{
sum++;
best++;
}
else
{
best = sum-1;
sum = max(sum-1, 0);
}
ans = max(ans, best);
}
}
}
printf("%d\n", ans);
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... |