답안 #433640

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
433640 2021-06-20T09:04:16 Z LouayFarah Election (BOI18_election) C++14
28 / 100
3000 ms 640 KB
#include "bits/stdc++.h"
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef long long ll;
typedef string str;
typedef double db;
typedef long double ld;
typedef pair<int, int> pi;
#define fi first
#define se second

#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)

const ll MOD = 1e9 + 7; //998244353
const ll INF = 1e18;
const ll MX = 1e9 + 10;
const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; //right left down up

#ifndef LOCAL
#define cerr if(false) cerr
#endif
#define debug(x) cerr << #x << " : " << x << endl;
#define debugs(x,y) cerr << #x << " : " << x << " / " << #y << " : " << y << endl;
#define debugv(v) cerr << #v << " : " << "[ "; for(auto it : v) cerr << it << ' '; cerr << ']' << endl;
#define here() cerr << "here" << endl;

void IO() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

struct segtree
{
    int size;
    vector<ll> sums;

    void init(int n)
    {
        size = 1;
        while(size<n) size*=2;
        sums.assign(2*size, 1e9);
    }

    void set(int i, int v, int x, int lx, int rx)
    {
        if(rx-lx==1)
        {
            sums[x] = v;
            return;
        }

        int mid = (lx+rx)/2;

        if(i<mid)
            set(i, v, 2*x+1, lx, mid);
        else
            set(i, v, 2*x+2, mid, rx);

        sums[x] = min(sums[2*x+1], sums[2*x+2]);
    }

    void set(int i, int v)
    {
        set(i, v, 0, 0, size);
    }


    ll sum(int l, int r, int x, int lx, int rx)
    {
        if(lx>=r||l>=rx) return 1e9;
        if(lx>=l&&rx<=r) return sums[x];

        int mid = (lx+rx)/2;
        ll s1 = sum(l, r, 2*x+1, lx, mid);
        ll s2 = sum(l, r, 2*x+2, mid, rx);
        return min(s1, s2);
    }

    ll sum(int l, int r)
    {
        return sum(l, r, 0, 0, size);
    }
};

int main()
{
    boost;
    IO();

    ll n;
    cin >> n;

    string s;
    cin >> s;


    ll q;
    cin >> q;
    while(q--)
    {
        ll l, r;
        cin >> l >> r;
        l--;
        vector<bool> nullified(n, false);

        ll temp = 0;
        ll res = 0;
        for(int i = l; i<r; i++)
        {
            if(s[i]=='C')
            {
                if(!nullified[i])
                    temp++;
            }
            else
            {
                if(!nullified[i])
                    temp--;
            }
            if(temp<0)
            {
                temp = 0;
                res++;
                nullified[i] = true;
            }
        }

        temp = 0;
        for(int i = r-1; i>=l; i--)
        {
            if(s[i]=='C')
            {
                if(!nullified[i])
                    temp++;
            }
            else
            {
                if(!nullified[i])
                    temp--;
            }
            if(temp<0)
            {
                temp = 0;
                res++;
                nullified[i] = true;
            }
        }

        cout << res << endl;
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 204 KB Output is correct
2 Correct 8 ms 320 KB Output is correct
3 Correct 7 ms 204 KB Output is correct
4 Correct 8 ms 204 KB Output is correct
5 Correct 5 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 204 KB Output is correct
2 Correct 8 ms 320 KB Output is correct
3 Correct 7 ms 204 KB Output is correct
4 Correct 8 ms 204 KB Output is correct
5 Correct 5 ms 320 KB Output is correct
6 Execution timed out 3088 ms 640 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 204 KB Output is correct
2 Correct 8 ms 320 KB Output is correct
3 Correct 7 ms 204 KB Output is correct
4 Correct 8 ms 204 KB Output is correct
5 Correct 5 ms 320 KB Output is correct
6 Execution timed out 3088 ms 640 KB Time limit exceeded
7 Halted 0 ms 0 KB -