# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
871656 |
2023-11-11T08:39:23 Z |
vjudge1 |
Difference (POI11_roz) |
C++17 |
|
1000 ms |
23224 KB |
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int maxn = 1e6+55;
const int inf = 1e9+55;
typedef pair <int,int> pii;
int a[maxn], b[maxn];
int cnt[maxn], n;
int pref[maxn], cntPref[maxn];
int cal(int c1, int c2)
{
vector <int> rem;
rem.push_back(0);
for (int i = 1; i <= n; i ++)
{
if (a[i] == c1) rem.push_back(1);
else rem.push_back(-1);
}
int m = rem.size();
for (int i = 1; i <= m; i ++) cntPref[i] = cntPref[i-1] + (rem[i] == -1);
for (int i = 1; i <= m; i ++) pref[i] = pref[i-1] + rem[i];
int j = 0, mn = inf, best = 0;
for (int i = 1; i <= m; i ++)
{
while (j < i && cntPref[i] - cntPref[j-1] > 0)
{
mn = min(mn, pref[j]);
j ++;
}
best = max(best, pref[i] - mn);
}
return best;
}
void process()
{
cin >> n;
for (int i = 1; i <= n; i ++)
{
char x;
cin >> x;
a[i] = x - 'a';
}
int best = 0;
for (int c1 = 0; c1 < 26; c1 ++) for (int c2 = 0; c2 < 26; c2 ++) if (c1 != c2)
{
best = max(best, cal(c1, c2));
}
cout << best;
}
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int ntest = 1;
while (ntest --) process();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
53 ms |
4700 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
677 ms |
10328 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1044 ms |
22896 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1058 ms |
23164 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1057 ms |
22876 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1018 ms |
23224 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |