Submission #166746

#TimeUsernameProblemLanguageResultExecution timeMemory
166746stefdascaJOIOJI (JOI14_joioji)C++14
100 / 100
56 ms6276 KiB
#include<bits/stdc++.h> #define god dimasi5eks #pragma GCC optimize("O3") #define fi first #define se second #define pb push_back #define pf push_front #define mod 1000000007 #define dancila 3.14159265359 #define eps 1e-9 using namespace std; typedef long long ll; int add(int a, int b) { ll x = a+b; if(x >= mod) x -= mod; if(x < 0) x += mod; return x; } ll mul(ll a, ll b) { return (a*b) % mod; } ll pw(ll a, ll b) { ll ans = 1; while(b) { if(b & 1) ans = (ans * a) % mod; a = (a * a) % mod; b >>= 1; } return ans; } map<pair<int, pair<int, int> >, int> mp; int n; string s; int v[5]; int ans; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; cin >> s; mp[{0, {0, 0}}] = -1; for(int i = 0; i < n; ++i) { if(s[i] == 'J') ++v[1]; if(s[i] == 'O') ++v[2]; if(s[i] == 'I') ++v[3]; int mn = min(v[1], min(v[2], v[3])); if(mp.find({v[1] - mn, {v[2] - mn, v[3] - mn}}) != mp.end()) ans = max(ans, i - mp[{v[1] - mn, {v[2] - mn, v[3] - mn}}]); else mp[{v[1] - mn, {v[2] - mn, v[3] - mn}}] = i; } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...