Submission #361974

#TimeUsernameProblemLanguageResultExecution timeMemory
361974kshitij_sodaniElection (BOI18_election)C++14
28 / 100
3090 ms2912 KiB
//#pragma GCC optimize("Ofast,unroll-loops") #include <bits/stdc++.h> using namespace std; typedef long long llo; #define mp make_pair #define pb push_back #define a first #define b second #define endl '\n' int n; int it[500001]; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>n; string s; cin>>s; for(int i=0;i<n;i++){ if(s[i]=='T'){ it[i]=-1; } else{ it[i]=1; } //cout<<it[i]<<","; } //cout<<endl; int q; cin>>q; while(q--){ int l,r; cin>>l>>r; l--; r--; int su=0; vector<int> kk; for(int i=l;i<=r;i++){ kk.pb(it[i]); } /* for(auto j:kk){ cout<<j<<","; } cout<<endl;*/ int ans=0; for(int i=0;i<kk.size();i++){ su+=kk[i]; if(su<0){ su-=kk[i]; kk[i]=0; // su+=kk[i]; ans++; } } su=0; for(int i=kk.size()-1;i>=0;i--){ su+=kk[i]; if(su<0){ su-=kk[i]; kk[i]=0; // su+=kk[i]; ans++; } } /* for(auto j:kk){ cout<<j<<","; } cout<<endl;*/ cout<<ans<<endl; } return 0; }

Compilation message (stderr)

election.cpp: In function 'int main()':
election.cpp:47:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |   for(int i=0;i<kk.size();i++){
      |               ~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...