# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
361974 | 2021-02-01T13:14:39 Z | kshitij_sodani | Election (BOI18_election) | C++14 | 3000 ms | 2912 KB |
//#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 364 KB | Output is correct |
2 | Correct | 5 ms | 364 KB | Output is correct |
3 | Correct | 5 ms | 364 KB | Output is correct |
4 | Correct | 6 ms | 364 KB | Output is correct |
5 | Correct | 5 ms | 364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 364 KB | Output is correct |
2 | Correct | 5 ms | 364 KB | Output is correct |
3 | Correct | 5 ms | 364 KB | Output is correct |
4 | Correct | 6 ms | 364 KB | Output is correct |
5 | Correct | 5 ms | 364 KB | Output is correct |
6 | Execution timed out | 3090 ms | 2912 KB | Time limit exceeded |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 364 KB | Output is correct |
2 | Correct | 5 ms | 364 KB | Output is correct |
3 | Correct | 5 ms | 364 KB | Output is correct |
4 | Correct | 6 ms | 364 KB | Output is correct |
5 | Correct | 5 ms | 364 KB | Output is correct |
6 | Execution timed out | 3090 ms | 2912 KB | Time limit exceeded |
7 | Halted | 0 ms | 0 KB | - |