Submission #1287248

#TimeUsernameProblemLanguageResultExecution timeMemory
1287248TrieTrJOIOJI (JOI14_joioji)C++20
95 / 100
32 ms6016 KiB
#include<bits/stdc++.h>
using namespace std;

void local() {
	#define taskname ""
	if(fopen(taskname".inp", "r")) {
		freopen(taskname".inp", "r", stdin);
		freopen(taskname".out", "w", stdout);
	}
}

#define ll long long
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

template <class X, class Y> bool mini(X& x, Y y) {return x > y ? x = y, true : false;}
template <class X, class Y> bool maxi(X& x, Y y) {return x < y ? x = y, true : false;}

const int N = 1e6 + 5;

int n;
string s;
array<int, 3> state;
map<array<int, 3>, int> mp;

int main() {
	fastio; local();
	cin >> n >> s; s = '#' + s;
	state[0] = state[1] = state[2] = 0;
	int res = 0;
	for(int i = 1; i <= n; i++) {
		if(s[i] == 'J') state[0]--, state[1]++;
		if(s[i] == 'O') state[1]--, state[2]++;
		if(s[i] == 'I') state[2]--, state[0]++;
		if(mp.find(state) != mp.end()) {
			maxi(res, i - mp[state]);
		}
		else mp[state] = i;
	}
	cout << res;
	
}

Compilation message (stderr)

joioji.cpp: In function 'void local()':
joioji.cpp:7:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |                 freopen(taskname".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
joioji.cpp:8:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |                 freopen(taskname".out", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...