답안 #108421

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
108421 2019-04-29T09:19:52 Z win11905 Election (BOI18_election) C++11
28 / 100
3000 ms 2040 KB
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author win11905
 */

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define iii tuple<int, int, int>
#define long long long
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
const long MOD = 1e9+7, LINF = 1e18 + 1e16;
const int INF = 1e9+1;
const double EPS = 1e-10;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};

const int N = 5e5+5;

class election {
private:
    int n, m;
    char arr[N];
    bool st[N];
public:
    void solve(istream& cin, ostream& cout) {
        cin >> n;
        cin >> arr+1;
        cin >> m;
        for(int i = 0, l, r; i < m; ++i) {
            cin >> l >> r;
            int cnt = 0;
            set<int> s;
            for(int i = l; i <= r; ++i) {
                cnt += arr[i] == 'C' ? 1 : -1;
                if(cnt < 0) s.emplace(i), cnt++;
            }
            cnt = 0;
            for(int i = r; i >= l; --i) {
                if(s.count(i)) continue;
                cnt += arr[i] == 'C' ? 1 : -1;
                if(cnt < 0) s.emplace(i), cnt++;
            }
            cout << s.size() << endl;
        }
    }
};

class Solver {
public:
    void solve(std::istream& in, std::ostream& out) {
        election *obj = new election();
        obj->solve(in, out);
    }
};

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    Solver solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}

Compilation message

election.cpp: In member function 'void election::solve(std::istream&, std::ostream&)':
election.cpp:31:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         cin >> arr+1;
                ~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 1408 KB Output is correct
2 Correct 22 ms 1280 KB Output is correct
3 Correct 14 ms 1408 KB Output is correct
4 Correct 56 ms 1408 KB Output is correct
5 Correct 41 ms 1408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 1408 KB Output is correct
2 Correct 22 ms 1280 KB Output is correct
3 Correct 14 ms 1408 KB Output is correct
4 Correct 56 ms 1408 KB Output is correct
5 Correct 41 ms 1408 KB Output is correct
6 Execution timed out 3025 ms 2040 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 1408 KB Output is correct
2 Correct 22 ms 1280 KB Output is correct
3 Correct 14 ms 1408 KB Output is correct
4 Correct 56 ms 1408 KB Output is correct
5 Correct 41 ms 1408 KB Output is correct
6 Execution timed out 3025 ms 2040 KB Time limit exceeded
7 Halted 0 ms 0 KB -