Submission #730245

# Submission time Handle Problem Language Result Execution time Memory
730245 2023-04-25T13:29:32 Z nguyentunglam Election (BOI18_election) C++17
28 / 100
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

election.cpp: In function 'int main()':
election.cpp:13:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         freopen ("task.inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
election.cpp:14:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         freopen ("task.out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
election.cpp:17:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
election.cpp:18:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen (task".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory 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
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory 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 -