Submission #137574

# Submission time Handle Problem Language Result Execution time Memory
137574 2019-07-28T06:44:33 Z mechfrog88 Election (BOI18_election) C++14
28 / 100
3000 ms 1100 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll n,q;
    cin >> n;
    string a;
    cin >> a;
    cin >> q;
    for (int z=0;z<q;z++){
        ll l,r;
        cin >> l >> r;
        l--;r--;
        ll c = 0;
        ll t = 0;
        vector <bool> arr(n,false);
        for (int x=l;x<=r;x++){
            if (a[x] == 'C'){
                c++;
            } else {
                t++;
            }
            if (t > c){
                t--;
                arr[x] = true;
            }
        }
        c = 0;
        t = 0;
        for (int x=r;x>=l;x--){
            if (a[x] == 'C'){
                c++;
            } else if (!arr[x]){
                t++;
            }
            if (t > c){
                t--;
                arr[x] = true;
            }
        }
        ll ans = 0;
        for (int z=0;z<n;z++){
            if (arr[z]) ans++;
        }
        cout << ans << endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 25 ms 504 KB Output is correct
2 Correct 25 ms 376 KB Output is correct
3 Correct 23 ms 376 KB Output is correct
4 Correct 24 ms 504 KB Output is correct
5 Correct 18 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 504 KB Output is correct
2 Correct 25 ms 376 KB Output is correct
3 Correct 23 ms 376 KB Output is correct
4 Correct 24 ms 504 KB Output is correct
5 Correct 18 ms 376 KB Output is correct
6 Execution timed out 3010 ms 1100 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 504 KB Output is correct
2 Correct 25 ms 376 KB Output is correct
3 Correct 23 ms 376 KB Output is correct
4 Correct 24 ms 504 KB Output is correct
5 Correct 18 ms 376 KB Output is correct
6 Execution timed out 3010 ms 1100 KB Time limit exceeded
7 Halted 0 ms 0 KB -