Submission #759430

# Submission time Handle Problem Language Result Execution time Memory
759430 2023-06-16T09:37:02 Z Bula Election (BOI18_election) C++17
0 / 100
4 ms 372 KB
#include<bits/stdc++.h>
using namespace std;

#define int long long
const int mod=1e9+7;

main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	int n;
	cin>>n;
	string s;
	cin>>s;
	vector<int> v(n+1),pref(n+1),suf(n+2);
	for(int i=1;i<=n;i++){
		if(s[i-1]=='T') v[i]=1;
		else v[i]=-1;
	}
	
	for(int i=1;i<=n;i++){
		pref[i]=pref[i-1]+v[i];
	}	
	for(int i=n;i>=1;i--){
		suf[i]=suf[i+1]+v[i];
	}
	
	int q;
	cin>>q;
	for(int i=0;i<q;i++){
		int l,r;
		cin>>l>>r;
		int ans=0;
		for(int j=l;j<=r;j++){
			ans=max(ans,max(pref[j]-pref[l-1],suf[j]-suf[r+1]));
		}
		cout<<ans<<endl;
	}
}

Compilation message

election.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    7 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 372 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 372 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 372 KB Output isn't correct
2 Halted 0 ms 0 KB -