Submission #947618

#TimeUsernameProblemLanguageResultExecution timeMemory
947618LOLOLOJOIOJI (JOI14_joioji)C++17
100 / 100
20 ms14628 KiB
#include <bits/stdc++.h> typedef long long ll; #define f first #define s second #define pb push_back #define ep emplace #define eb emplace_back #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin()) #define mem(f,x) memset(f , x , sizeof(f)) #define sz(x) (int)(x).size() #define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b)) #define mxx *max_element #define mnn *min_element #define cntbit(x) __builtin_popcountll(x) using namespace std; const int N = 4e5 + 100; const int M = 2e5; int p[N], pr[N]; vector <int> pos[N]; int solve() { int n; cin >> n; string s; cin >> s; s = '0' + s; p[0] = M; pos[M].pb(0); for (int i = 1; i <= n; i++) { if (s[i] == 'J') { p[i]++; } if (s[i] == 'O') { p[i]--; } if (s[i] == 'I') { pr[i]++; } pr[i] += pr[i - 1]; p[i] += p[i - 1]; pos[p[i]].pb(i); } int ans = 0; for (int i = 0; i < N; i++) { if (pos[i].empty()) continue; map <int, int> mp; for (auto x : pos[i]) { int cur = x - pr[x] * 3; if (mp.find(cur) != mp.end()) { ans = max(ans, x - mp[cur]); } else { mp[cur] = x; } } } return ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; //cin >> t; while (t--) { cout << solve() << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...