Submission #855207

#TimeUsernameProblemLanguageResultExecution timeMemory
855207QuangBui새로운 문제 (POI11_roz)C++14
100 / 100
717 ms12224 KiB
// QuangBuiCP #include "bits/stdc++.h" using namespace std; #define SZ(a) (int)(a).size() #define ALL(a) (a).begin(),(a).end() signed main() { #ifndef LOCAL cin.tie(nullptr)->sync_with_stdio(false); #endif // LOCAL int n; cin >> n; vector<vector<int>> pos(26); for (int i = 1; i <= n; ++i) { char c; cin >> c; pos[int(c - 'a')].push_back(i); } int ans = 0; for (int x = 0; x < 26; ++x) { for (int y = 0; y < 26; ++y) { if (x == y) { continue; } if (!SZ(pos[x]) || !SZ(pos[y])) { continue; } vector<int> a = {0}; { int j = 0; for (int i : pos[x]) { while (j < SZ(pos[y]) && pos[y][j] < i) { a.push_back(-1); j++; } a.push_back(1); } while (j < SZ(pos[y])) { a.push_back(-1); j++; } } #ifdef LOCAL cerr << x << ' ' << y << ": "; for (int it : a) { cerr << it << ' '; } cerr << '\n'; #endif // LOCAL int sz = SZ(a); int mn = n + 1, lst = 0; vector<int> pref(sz, 0); for (int i = 1; i < sz; ++i) { pref[i] = pref[i - 1] + a[i]; if (i > 1 && a[i] != a[i - 1]) { for (int j = lst; j < i - 1; ++j) { mn = min(mn, pref[j]); } lst = i - 1; } ans = max(ans, pref[i] - mn); } } } cout << ans << '\n'; #ifdef LOCAL cerr << '\n' << clock() << "ms."; #endif // LOCAL return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...