# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
730245 | 2023-04-25T13:29:32 Z | nguyentunglam | Election (BOI18_election) | C++17 | 3000 ms | 2248 KB |
#include<bits/stdc++.h> #define fi first #define se second #define endl "\n" #define ii pair<int, int> using namespace std; const int N = 5e5 + 10; int a[N], b[N]; int main() { #define task "" cin.tie(0) -> sync_with_stdio(0); if (fopen ("task.inp", "r")) { freopen ("task.inp", "r", stdin); freopen ("task.out", "w", stdout); } if (fopen (task".inp", "r")) { freopen (task".inp", "r", stdin); freopen (task".out", "w", stdout); } int n; cin >> n; string s; cin >> s; s = " " + s; for(int i = 1; i <= n; i++) { if (s[i] == 'C') a[i] = 1; else a[i] = -1; } int q; cin >> q; while (q--) { for(int i = 1; i <= n; i++) b[i] = a[i]; int l, r, ans = 0; cin >> l >> r; int sum = 0; for(int i = l; i <= r; i++) { sum += b[i]; if (sum < 0) { sum = 0; ans++; b[i] = 0; } } sum = 0; int ans2 = 0; for(int i = r; i >= l; i--) { sum += b[i]; ans2 = max(ans2, -sum); } cout << ans + ans2 << endl; } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 468 KB | Output is correct |
2 | Correct | 4 ms | 392 KB | Output is correct |
3 | Correct | 4 ms | 340 KB | Output is correct |
4 | Correct | 6 ms | 340 KB | Output is correct |
5 | Correct | 4 ms | 340 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 468 KB | Output is correct |
2 | Correct | 4 ms | 392 KB | Output is correct |
3 | Correct | 4 ms | 340 KB | Output is correct |
4 | Correct | 6 ms | 340 KB | Output is correct |
5 | Correct | 4 ms | 340 KB | Output is correct |
6 | Correct | 2803 ms | 2248 KB | Output is correct |
7 | Execution timed out | 3077 ms | 1656 KB | Time limit exceeded |
8 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 468 KB | Output is correct |
2 | Correct | 4 ms | 392 KB | Output is correct |
3 | Correct | 4 ms | 340 KB | Output is correct |
4 | Correct | 6 ms | 340 KB | Output is correct |
5 | Correct | 4 ms | 340 KB | Output is correct |
6 | Correct | 2803 ms | 2248 KB | Output is correct |
7 | Execution timed out | 3077 ms | 1656 KB | Time limit exceeded |
8 | Halted | 0 ms | 0 KB | - |