답안 #789078

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
789078 2023-07-21T02:15:30 Z Genius3435 Election (BOI18_election) C++17
28 / 100
3000 ms 1608 KB
#include <bits/stdc++.h>
using namespace std;

int constexpr N = 1<<19;
int upd[N];
char s[N];
int ss[N];

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n; cin >> n >> s;
    for (int i = 0; i < n; ++i) ss[i] = s[i] == 'C' ? 1 : -1;

    int q; cin >> q;
    for (int qi = 1; qi <= q; ++qi) {
        int l, r; cin >> l >> r; --l;

        int ans = 0;
        for (int i = l, c = 0; i < r; ++i) {
            c += ss[i];
            if (c < 0) ++c, ++ans, upd[i] = qi;
        }
        for (int i = r-1, c = 0; i >= l; --i) {
            c += ss[i] + (upd[i] == qi);
            if (c < 0) ++c, ++ans;
        }

        cout << ans << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 2074 ms 1608 KB Output is correct
7 Execution timed out 3049 ms 1440 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 2074 ms 1608 KB Output is correct
7 Execution timed out 3049 ms 1440 KB Time limit exceeded
8 Halted 0 ms 0 KB -