# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1002327 |
2024-06-19T12:33:56 Z |
Sang |
Difference (POI11_roz) |
C++14 |
|
608 ms |
13144 KB |
// Created by Sang lớp 9
// Какого черта ты переводишь?
#include <bits/stdc++.h>
using namespace std;
#define Sang 1
// #define int long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'
#define FOR(i, a, b) for(__typeof(b) i = a, _b = b; i <= _b; ++i)
#define FORD(i, a, b) for(__typeof(a) i = a, _b = b; i >= _b; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MASK(i) (1ll<<(i))
#define BIT(t, i) (((t)>>(i))&1)
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, ii> pii;
const int MOD = 1e9+7;
const int N = 1e5+5;
const int INF = 0x3f3f3f3f;
template <class T> bool minimize(T &a, T b) { if (a > b) { a = b; return true; } return false;}
template <class T> bool maximize(T &a, T b) { if (a < b) { a = b; return true; } return false;}
// **** ****
// * * *
// * K.B *
// * *
// * *
int n;
vi pos[30];
int cal(int x, int y){
vi b;
if (x == y) return 0;
if (pos[x].size() == 0 || pos[y].size() == 0) return 0;
int i = 0, j = 0;
while (i < pos[x].size() && j < pos[y].size()){
if (pos[x][i] < pos[y][j]){
b.pb(-1);
i++;
} else {
b.pb(1);
j++;
}
}
while (j < pos[y].size()){
b.pb(1);
j++;
}
while (i < pos[x].size()){
b.pb(-1);
i++;
}
int mi = INF, sum = 0, ans = 0, ok = 0, last = 0;
for (int x : b){
if (x == -1) minimize(mi, last);
sum += x;
maximize(ans, sum-mi);
minimize(last, sum);
}
return ans;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
#ifndef Sang
freopen("DIFFER.inp", "r", stdin);
freopen("DIFFER.out", "w", stdout);
#endif
cin >> n;
FOR (i, 1, n){
char c; cin >> c;
pos[c-'a'].pb(i);
}
int ans = 0;
FOR (i, 'a', 'z'){
FOR (j, 'a', 'z'){
maximize(ans, cal(i-'a', j-'a'));
}
}
cout << ans;
return 0;
}
Compilation message
roz.cpp: In function 'int cal(int, int)':
roz.cpp:43:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | while (i < pos[x].size() && j < pos[y].size()){
| ~~^~~~~~~~~~~~~~~
roz.cpp:43:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | while (i < pos[x].size() && j < pos[y].size()){
| ~~^~~~~~~~~~~~~~~
roz.cpp:52:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | while (j < pos[y].size()){
| ~~^~~~~~~~~~~~~~~
roz.cpp:56:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | while (i < pos[x].size()){
| ~~^~~~~~~~~~~~~~~
roz.cpp:60:37: warning: unused variable 'ok' [-Wunused-variable]
60 | int mi = INF, sum = 0, ans = 0, ok = 0, last = 0;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
860 KB |
Output is correct |
2 |
Correct |
0 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
562 ms |
6744 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
345 ms |
5560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
596 ms |
6816 KB |
Output is correct |
2 |
Correct |
454 ms |
5320 KB |
Output is correct |
3 |
Correct |
157 ms |
6236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
576 ms |
6864 KB |
Output is correct |
2 |
Correct |
73 ms |
12088 KB |
Output is correct |
3 |
Correct |
110 ms |
7392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
608 ms |
6752 KB |
Output is correct |
2 |
Correct |
42 ms |
13144 KB |
Output is correct |
3 |
Correct |
189 ms |
7116 KB |
Output is correct |