Submission #956525

# Submission time Handle Problem Language Result Execution time Memory
956525 2024-04-02T06:41:55 Z moonrabbit2 Election (BOI18_election) C++17
28 / 100
3000 ms 4148 KB
#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...)
#endif
const int N=500005;
int n,a[N],q;
bool chk[N];
string s;
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	cin>>n>>s>>q;
	for(int i=1;i<=n;i++){
		if(s[i-1]=='C') a[i]=1;
		else a[i]=-1;
	}
	for(int l,r,t=1;t<=q;t++){
		cin>>l>>r;
		int s=0,ans=0,mn=0;
		for(int i=l;i<=r;i++){
			if(s+a[i]<0){
				chk[i]=1;
				ans++;
			} else{
				s+=a[i];
				chk[i]=0;
			}
		}
		s=0;
		for(int i=r;i>=l;i--) if(!chk[i]){
			s+=a[i];
			mn=min(mn,s);
		}
		ans-=mn;
		cout<<ans<<"\n";
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2524 KB Output is correct
2 Correct 2 ms 2524 KB Output is correct
3 Correct 2 ms 2536 KB Output is correct
4 Correct 3 ms 2396 KB Output is correct
5 Correct 2 ms 2548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2524 KB Output is correct
2 Correct 2 ms 2524 KB Output is correct
3 Correct 2 ms 2536 KB Output is correct
4 Correct 3 ms 2396 KB Output is correct
5 Correct 2 ms 2548 KB Output is correct
6 Correct 1220 ms 3916 KB Output is correct
7 Execution timed out 3055 ms 4148 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2524 KB Output is correct
2 Correct 2 ms 2524 KB Output is correct
3 Correct 2 ms 2536 KB Output is correct
4 Correct 3 ms 2396 KB Output is correct
5 Correct 2 ms 2548 KB Output is correct
6 Correct 1220 ms 3916 KB Output is correct
7 Execution timed out 3055 ms 4148 KB Time limit exceeded
8 Halted 0 ms 0 KB -