Submission #166418

# Submission time Handle Problem Language Result Execution time Memory
166418 2019-12-02T10:17:11 Z Atill83 Election (BOI18_election) C++14
28 / 100
3000 ms 1628 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 3e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n;
string s;
set<int> indices;
vector<pair<int, char>> vc;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);

    #ifdef Local
        freopen("../IO/int.txt","r",stdin);
        freopen("../IO/out.txt","w",stdout);
    #endif

    cin>>n;
    cin>>s;
    s = '.' + s;
    int q;
    cin>>q;
    while(q--){
        vc.clear();
        int l, r;
        cin>>l>>r;
        for(int i = l; i <= r;){
            int cnt = 1;
            while(i < r && s[i + 1] == s[i]){
                i++;
                cnt++;
            }
            vc.push_back({cnt, s[i]});
            i++;
        }
        int cur = 0;
        int ans = 0;
        for(int i = 0; i < vc.size(); i++){
            if(vc[i].ss == 'T'){
                cur -= vc[i].ff;
            }else{
                cur += vc[i].ff;
            }
            if(cur < 0){
                vc[i].ff += cur;
                ans += -cur;
                cur = 0;
            }
        }
        cur = 0;
        for(int i = vc.size() - 1; i >= 0; i--){
            if(vc[i].ss =='T'){
                cur -= vc[i].ff;
            }else{
                cur += vc[i].ff;
            }
            if(cur < 0){
                vc[i].ff += cur;
                ans += -cur;
                cur = 0;
            }
        }
        cout<<ans<<endl;
    }

    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}

Compilation message

election.cpp: In function 'int main()':
election.cpp:47:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0; i < vc.size(); i++){
                        ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 376 KB Output is correct
2 Correct 10 ms 376 KB Output is correct
3 Correct 10 ms 376 KB Output is correct
4 Correct 10 ms 376 KB Output is correct
5 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 376 KB Output is correct
2 Correct 10 ms 376 KB Output is correct
3 Correct 10 ms 376 KB Output is correct
4 Correct 10 ms 376 KB Output is correct
5 Correct 4 ms 376 KB Output is correct
6 Execution timed out 3023 ms 1628 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 376 KB Output is correct
2 Correct 10 ms 376 KB Output is correct
3 Correct 10 ms 376 KB Output is correct
4 Correct 10 ms 376 KB Output is correct
5 Correct 4 ms 376 KB Output is correct
6 Execution timed out 3023 ms 1628 KB Time limit exceeded
7 Halted 0 ms 0 KB -