# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
696335 | 2023-02-06T09:08:08 Z | dongliu0426 | Difference (POI11_roz) | C++17 | 620 ms | 33672 KB |
#pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <iostream> #include <vector> using namespace std; const int N = 1e6; int main() { int n; scanf("%d", &n); static char s[N]; scanf("%s", s); static vector<int> u[N]; for (int i = 0; i < n; i++) u[s[i] - 'a'].push_back(i); int ans = 0; for (int i = 0; i < 26; i++) for (int j = 0; j < 26; j++) { if (i == j) continue; static int t[N + 1]; int m = 0, l = 0, r = 0; while (l < (int) u[i].size() || r < (int) u[j].size()) if (l == (int) u[i].size()) t[++m] = -1, r++; else if (r == (int) u[j].size()) t[++m] = +1, l++; else if (u[i][l] < u[j][r]) t[++m] = +1, l++; else t[++m] = -1, r++; int p = 0, c = 0, d = 0, mn = n; for (int k = 1; k <= m; k++) { c += t[k]; if (t[k] == -1) { for (int k_ = p; k_ < k; k_++) mn = min(mn, d += t[k_]); p = k; } ans = max(ans, c - mn); } } printf("%d\n", ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 23764 KB | Output is correct |
2 | Correct | 11 ms | 23732 KB | Output is correct |
3 | Correct | 11 ms | 23800 KB | Output is correct |
4 | Correct | 11 ms | 23764 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 23716 KB | Output is correct |
2 | Correct | 11 ms | 23684 KB | Output is correct |
3 | Correct | 11 ms | 23740 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 23764 KB | Output is correct |
2 | Correct | 11 ms | 23764 KB | Output is correct |
3 | Correct | 13 ms | 23804 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 23824 KB | Output is correct |
2 | Correct | 11 ms | 23884 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 23892 KB | Output is correct |
2 | Correct | 15 ms | 23732 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 74 ms | 24404 KB | Output is correct |
2 | Correct | 12 ms | 23808 KB | Output is correct |
3 | Correct | 15 ms | 23892 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 615 ms | 30352 KB | Output is correct |
2 | Correct | 11 ms | 23764 KB | Output is correct |
3 | Correct | 364 ms | 29348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 620 ms | 30228 KB | Output is correct |
2 | Correct | 460 ms | 29292 KB | Output is correct |
3 | Correct | 153 ms | 29616 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 616 ms | 30148 KB | Output is correct |
2 | Correct | 197 ms | 32288 KB | Output is correct |
3 | Correct | 164 ms | 30684 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 602 ms | 29916 KB | Output is correct |
2 | Runtime error | 178 ms | 33672 KB | Memory limit exceeded |
3 | Halted | 0 ms | 0 KB | - |