Submission #759430

#TimeUsernameProblemLanguageResultExecution timeMemory
759430BulaElection (BOI18_election)C++17
0 / 100
4 ms372 KiB
#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 (stderr)

election.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    7 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...