Submission #920495

#TimeUsernameProblemLanguageResultExecution timeMemory
920495MilosMilutinovic스탬프 수집 (JOI16_ho_t2)C++14
100 / 100
3 ms636 KiB
#include<bits/stdc++.h>
 
#define pb push_back
#define fi first
#define se second
#define mp make_pair
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
 
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}
 
ll readint(){
	ll x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n;
char s[100005];

int main(){
	n=readint();
	scanf("%s",s+1);
	ll res=0;
	ll a=0,b=0;
	for(int i=1;i<=n;i++){
		if(s[i]=='J') a++;
		if(s[i]=='O') b+=a;
		if(s[i]=='I') res+=b;
	}
	ll mx=0;
	{
		a=0; b=0;
		for(int i=n;i>=1;i--){
			if(s[i]=='I') a++;
			if(s[i]=='O') b+=a;
			mx=max(mx,b);
		}
	}
	{
		a=0; b=0;
		for(int i=1;i<=n;i++) b+=(s[i]=='I'?1:0);
		for(int i=1;i<=n;i++){
			b-=(s[i]=='I'?1:0);
			a+=(s[i]=='J'?1:0);
			mx=max(mx,a*b);
		}
	}
	{
		a=0; b=0;
		for(int i=1;i<=n;i++){
			if(s[i]=='J') a++;
			if(s[i]=='O') b+=a;
			mx=max(mx,b);
		}
	}
	res+=mx;
	printf("%lld\n",res);
	return 0;
}

Compilation message (stderr)

2016_ho_t2.cpp: In function 'int main()':
2016_ho_t2.cpp:31:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |  scanf("%s",s+1);
      |  ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...