Submission #369806

#TimeUsernameProblemLanguageResultExecution timeMemory
369806mathking1021JOIOJI (JOI14_joioji)C++17
100 / 100
81 ms11640 KiB
#include <iostream> #include <cstdio> #include <map> #define PLL pair<ll, ll> #define F first #define S second using namespace std; typedef long long ll; ll n; string s; ll a, b, ans; map<PLL, ll> ma1, ma2; int main() { cin>>n>>s; ma1[make_pair(0, 0)] = ma2[make_pair(0, 0)] = 1; for(ll i = 0; i < n; i++) { if(s[i] == 'J') { a++; } else if(s[i] == 'O') { a--, b++; } else { b--; } if(!ma1.count(make_pair(a, b))) ma1[make_pair(a, b)] = i + 2; ma2[make_pair(a, b)] = i + 2; } for(auto i:ma1) { ll t1 = i.F.F; ll t2 = i.F.S; ll t3 = i.S; ans = max(ans, ma2[make_pair(t1, t2)] - t3); } printf("%lld\n", ans); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...