# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
885113 | 2023-12-09T03:00:42 Z | catlover | Difference (POI11_roz) | C++14 | 598 ms | 36876 KB |
#include <bits/stdc++.h> #define file(task) if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } #define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i) #define FORD(i, a, b) for(int i = (a), _b = (b); i >= _b; --i) #define pb push_back #define SZ(X) (int)((X).size()) using namespace std; const int maxN = 1e6; int N; string s; vector<int> id[maxN+5]; void read_input() { cin >> N >> s; } void solve() { s = ' ' + s; FOR(i, 1, N) id[s[i] - 'a'].pb(i); int res = 0; FOR(x, 0, 25) { FOR(y, 0, 25) { if(SZ(id[x]) * SZ(id[y]) == 0) continue; vector<int> d; int j = 0; for(int i : id[x]) { while(j < SZ(id[y]) && id[y][j] < i) { ++j; d.pb(-1); } d.pb(1); } while(j < SZ(id[y])) { ++j; d.pb(-1); } int last = 0, mn = 1e9; vector<int> f(SZ(d), 0); FOR(i, 0, SZ(d) - 1) { f[i] = f[i - 1] + d[i]; if(i > 1 && d[i] != d[i - 1]) { FOR(j, last, i - 2) mn = min(mn, f[j]); last = i - 1; } res = max(res, f[i] - mn); } } } cout << res; } int main() { cin.tie(0)->sync_with_stdio(0); file("SSDIFF"); read_input(); solve(); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 23900 KB | Output is correct |
2 | Correct | 6 ms | 23900 KB | Output is correct |
3 | Correct | 5 ms | 23900 KB | Output is correct |
4 | Incorrect | 6 ms | 23868 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 23900 KB | Output is correct |
2 | Correct | 5 ms | 23900 KB | Output is correct |
3 | Correct | 5 ms | 23900 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 23896 KB | Output is correct |
2 | Correct | 5 ms | 23900 KB | Output is correct |
3 | Correct | 5 ms | 23900 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 23900 KB | Output is correct |
2 | Correct | 5 ms | 23940 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 23900 KB | Output is correct |
2 | Correct | 5 ms | 23896 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 63 ms | 24596 KB | Output is correct |
2 | Incorrect | 5 ms | 23900 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 584 ms | 31916 KB | Output is correct |
2 | Correct | 5 ms | 23900 KB | Output is correct |
3 | Correct | 291 ms | 29960 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 583 ms | 31684 KB | Output is correct |
2 | Correct | 431 ms | 30428 KB | Output is correct |
3 | Correct | 166 ms | 30748 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 585 ms | 31696 KB | Output is correct |
2 | Runtime error | 79 ms | 35644 KB | Memory limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 598 ms | 31568 KB | Output is correct |
2 | Runtime error | 49 ms | 36876 KB | Memory limit exceeded |
3 | Halted | 0 ms | 0 KB | - |