Submission #364858

#TimeUsernameProblemLanguageResultExecution timeMemory
364858Sparky_09JOIOJI (JOI14_joioji)C++17
100 / 100
45 ms6264 KiB
#include "bits/stdc++.h" using namespace std; #define rep(i, a, b) for(int i = a; i < (b); ++i) #define all(x) begin(x), end(x) #define trav(a, x) for(auto& a : x) #define sz(x) (int)(x).size() typedef long long ll; typedef pair<ll, ll> pii; typedef vector<ll> vi; typedef vector<pii> vpi; void usaco(string s){ freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); } int main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); #ifdef LOCAL_DEFINE freopen("input.txt", "r", stdin); #endif int n; cin >> n; string s; cin >> s; map<pair<int, int>, int> m; m[make_pair(0, 0)] = 0; int js=0,is=0,os=0,ans=0; rep(i, 0, n){ if(s[i]=='J') js++; else if(s[i]=='O') os++; else is++; if(m.find(make_pair(js-os,js-is))==m.end()) m[make_pair(js-os,js-is)] = i+1; else ans = max(ans, i+1-m[make_pair(js-os,js-is)]); } cout << ans << '\n'; }

Compilation message (stderr)

joioji.cpp: In function 'void usaco(std::string)':
joioji.cpp:13:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   13 |   freopen((s+".in").c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
joioji.cpp:14:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   14 |   freopen((s+".out").c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...