# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
885112 | 2023-12-09T02:56:41 Z | vjudge1 | Difference (POI11_roz) | C++17 | 582 ms | 13572 KB |
// Author : Hoang Van Tra - HSGS Bac Giang // Train VOI 2023 - 2024 #include <bits/stdc++.h> using namespace std; // -------------------------------------------------------INDEF----------------------------------------------------------------------- #define For(i,a,b) for(int i = a; i <= b; i++) #define Ford(i,a,b) for(int i = a; i >= b; i--) #define ll long long #define ii pair<int,int> #define fi first #define se second #define pb push_back #define all(v) v.begin(),v.end() #define RRH(v) v.resize(unique(all(v)) - v.begin()) const int N = 1e6+7; const int M = 1e9+7; const ll oo = 1e18; const int block = 708; int n; vector<int> id[30]; string s; // -------------------------------------------------------ENDEF---------------------------------------------------------------------- int32_t main() { ios::sync_with_stdio(0); cin.tie(0); #define TASK "ssdiff" if (fopen (".inp", "r")) { freopen (".inp", "r", stdin); freopen (".out", "w", stdout); } if(fopen(TASK".inp", "r")) { freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout); } cin >> n >> s; s = " " + s; For(i, 1, n) { id[s[i] - 'a'].push_back(i); } int res = 0; for (int x = 0; x < 26; x++) { for (int y = 0; y < 26; y++) { if (id[x].empty() || id[y].empty()) continue; if (x == y) continue; vector<int> a {0}; int j = 0; for (int i: id[x]) { while (j < id[y].size() && id[y][j] < i) { a.push_back(-1); j++; } a.push_back(1); } while (j < id[y].size()) { a.push_back(-1); j++; } int ans = 0, mini = M, last = 0; vector<int> pre (a.size(), 0); for (int i = 1; i < a.size(); i++) { pre[i] = pre[i - 1] + a[i]; if (i > 1 && a[i] != a[i - 1]) { for (int j = last; j < i - 1; j++) { mini = min(mini, pre[j]); } last = i - 1; } ans = max(ans, pre[i] - mini); } res = max(res, ans); } } cout << res; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 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 | 0 ms | 348 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 | 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 | 360 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 61 ms | 1124 KB | Output is correct |
2 | Correct | 0 ms | 344 KB | Output is correct |
3 | Correct | 5 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 579 ms | 8228 KB | Output is correct |
2 | Correct | 0 ms | 344 KB | Output is correct |
3 | Correct | 284 ms | 6360 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 582 ms | 7960 KB | Output is correct |
2 | Correct | 426 ms | 6880 KB | Output is correct |
3 | Correct | 149 ms | 7352 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 576 ms | 8224 KB | Output is correct |
2 | Correct | 62 ms | 12588 KB | Output is correct |
3 | Correct | 114 ms | 8212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 576 ms | 7972 KB | Output is correct |
2 | Correct | 38 ms | 13572 KB | Output is correct |
3 | Correct | 183 ms | 8264 KB | Output is correct |