Submission #850241

# Submission time Handle Problem Language Result Execution time Memory
850241 2023-09-16T07:56:24 Z Rifal Election (BOI18_election) C++14
0 / 100
1 ms 344 KB
#include <bits/stdc++.h>
#include <fstream>
#define endl '\n'
#define mod 998244353
#define INF 9000000000
#define cin fin
#define cout fout
//#define fi first
//#define se second
using namespace std;
ofstream fout("elections.out");
ifstream fin("elections.in");

int main()
{
    ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
    int n; cin >> n;
    string s; cin >> s;
    int q; cin >> q;
    while(q--) {
        int l, r; cin >> l >> r;
        bool ok[n] = {};
        int cur = 0;
        int ans = 0;
        for(int i = l-1; i < r; i++) {
            if(s[i] == 'C') {
                cur++;
            }
            else if(cur-1 >= 0) {
                cur--;
            }
            else {
                ok[i] = 1;
                ans++;
            }
        }
        cur = 0;
        for(int i = r-1; i >= l-1; i--) {
            if(s[i] == 'C') {
                cur++;
            }
            else if(cur-1 >= 0 && ok[i] == 0) {
                cur--;
            }
            else if(ok[i] == 0) {
                ans++;
            }
        }
        cout << ans << endl;
    }
 return 0;
}

# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -