# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
707368 |
2023-03-08T22:53:36 Z |
KLPP |
Election (BOI18_election) |
C++14 |
|
3000 ms |
1784 KB |
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int lld;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define trav(a,v) for(auto a:v)
void solve(){
/*freopen("cardgame.in", "r", stdin);
freopen("cardgame.out", "w", stdout);*/
int n,q;
cin>>n;
string s;
cin>>s;
cin>>q;
while(q--){
int l,r;
cin>>l>>r;
l--;r--;
lld sum=0;
lld pref=0;
lld ans=0;
rep(i,l,r+1){
lld x=1;
if(s[i]=='T')x*=-1;
sum+=x;
pref=max(0LL,pref+x);
ans=max(ans,pref);
}
cout<<ans-sum<<"\n";
}
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.precision(16);
int tt=1;
//cin>>tt;
rep(test,0,tt){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
328 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
328 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
1517 ms |
1784 KB |
Output is correct |
7 |
Execution timed out |
3074 ms |
1388 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
328 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
1517 ms |
1784 KB |
Output is correct |
7 |
Execution timed out |
3074 ms |
1388 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |