Submission #674823

# Submission time Handle Problem Language Result Execution time Memory
674823 2022-12-26T09:22:39 Z sudheerays123 JOIOJI (JOI14_joioji) C++17
0 / 100
1 ms 468 KB
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
const ll N = 2e5+5 , INF = 1e18 , MOD = 1e9+7;

vector<char> s(N);
ll n;

bool check(ll length){

	ll j=0,i=0,o=0;

	for(ll k = 1; k <= length; k++){
		if(s[k] == 'J') j++;
		else if(s[k] == 'O') o++;
		else i++;
	}

	if(j == i && i == o) return true;

	for(ll k = length+1; k <= n; k++){
		if(s[k-length] == 'J') j--;
		else if(s[k-length] == 'O') o--;
		else i--;

		if(s[k] == 'J') j++;
		else if(s[k] == 'O') o++;
		else i++;

		if(j == i && i == o) return true;
	}

	return false;
}

void solve(){

	cin >> n;
	for(ll i = 1; i <= n; i++) cin >> s[i];

	ll low = 1, high = (n/3);
	ll ans = 0;

	while(low <= high){
		ll mid = ((low+high)/2);

		if(check(mid*3ll)){
			ans = mid*3ll;
			low = mid+1;
		}
		else high = mid-1;
	}

	cout << ans << "\n";
}

int main(){

	fast;

	ll tc = 1;
	// cin >> tc;
	while(tc--) solve();

	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 468 KB Output is correct
2 Incorrect 1 ms 416 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -