답안 #850242

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
850242 2023-09-16T07:57:17 Z Rifal Election (BOI18_election) C++14
28 / 100
3000 ms 1364 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;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 5 ms 344 KB Output is correct
3 Correct 4 ms 348 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 3 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 5 ms 344 KB Output is correct
3 Correct 4 ms 348 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 3 ms 344 KB Output is correct
6 Execution timed out 3035 ms 1364 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 5 ms 344 KB Output is correct
3 Correct 4 ms 348 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 3 ms 344 KB Output is correct
6 Execution timed out 3035 ms 1364 KB Time limit exceeded
7 Halted 0 ms 0 KB -