답안 #173449

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
173449 2020-01-04T07:16:06 Z ahgus89 JOIOJI (JOI14_joioji) C++14
0 / 100
2 ms 504 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int n, m, k, ans, mod=1e9+7;
int J[202020], O[202020], I[202020];
bool chk(int x)
{
	for(int i=0;i+3*x<=n;i++)
		if(J[i+3*x]-J[i]==x&&O[i+3*x]-O[i]==x&&I[i+3*x]-I[i]==x) return 1;
	return 0;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int i, temp=0;
	string s;
	cin>>n>>s;
	for(i=1;i<=n;i++)
	{
		J[i]=J[i-1];
		O[i]=O[i-1];
		I[i]=I[i-1];
		if(s[i-1]=='J') J[i]++;
		if(s[i-1]=='O') O[i]++;
		if(s[i-1]=='I') I[i]++;
	}
	int lo=0, hi=n/3;
	while(lo<hi)
	{
		int mid=lo+hi+1>>1;
		if(chk(mid)) lo=mid;
		else hi=mid-1;
	}
	cout<<lo*3;
}

Compilation message

joioji.cpp: In function 'int main()':
joioji.cpp:32:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid=lo+hi+1>>1;
           ~~~~~^~
joioji.cpp:17:9: warning: unused variable 'temp' [-Wunused-variable]
  int i, temp=0;
         ^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -