Submission #166418

#TimeUsernameProblemLanguageResultExecution timeMemory
166418Atill83Election (BOI18_election)C++14
28 / 100
3023 ms1628 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...