Submission #611110

# Submission time Handle Problem Language Result Execution time Memory
611110 2022-07-29T03:05:25 Z talant117408 Election (BOI18_election) C++17
28 / 100
9 ms 724 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

#define long                unsigned long 
#define pb                  push_back
#define mp                  make_pair
#define all(v)              (v).begin(),(v).end()
#define rall(v)             (v).rbegin(),(v).rend()
#define lb                  lower_bound
#define ub                  upper_bound
#define sz(v)               int((v).size())
#define do_not_disturb      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl                '\n'
#define PI                  2*acos(0.0)

void solve(int test) {
    int n;
    cin >> n;
    string votes;
    cin >> votes;
    votes = '1' + votes;
    int q;
    cin >> q;
    if (n <= 2000 && q <= 2000) {
        while (q--) {
            int l, r;
            cin >> l >> r;
            int balance = 0;
            vector <int> used(n + 1);
            for (int i = l; i <= r; i++) {
                balance += (votes[i] == 'C' ? 1 : -1);
                if (balance < 0) {
                    balance = 0;
                    used[i] = 1;
                }
            }
            balance = 0;
            for (int i = r; i >= l; i--) {
                if (used[i] == 1) continue;
                balance += (votes[i] == 'C' ? 1 : -1);
                if (balance < 0) {
                    balance = 0;
                    used[i] = 1;
                }
            }
            int ans = 0;
            for (auto to : used) ans += to;
            cout << ans << endl;
        }
    }
}  

int main() {
    do_not_disturb
    
    int t = 1;
    //~ cin >> t;
    for (int i = 1; i <= t; i++) {
        solve(i);
    }
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 340 KB Output is correct
2 Correct 9 ms 360 KB Output is correct
3 Correct 7 ms 340 KB Output is correct
4 Correct 8 ms 340 KB Output is correct
5 Correct 5 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 340 KB Output is correct
2 Correct 9 ms 360 KB Output is correct
3 Correct 7 ms 340 KB Output is correct
4 Correct 8 ms 340 KB Output is correct
5 Correct 5 ms 328 KB Output is correct
6 Incorrect 1 ms 724 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 340 KB Output is correct
2 Correct 9 ms 360 KB Output is correct
3 Correct 7 ms 340 KB Output is correct
4 Correct 8 ms 340 KB Output is correct
5 Correct 5 ms 328 KB Output is correct
6 Incorrect 1 ms 724 KB Output isn't correct
7 Halted 0 ms 0 KB -