Submission #63542

# Submission time Handle Problem Language Result Execution time Memory
63542 2018-08-02T06:05:23 Z antimirage Election (BOI18_election) C++17
28 / 100
24 ms 1240 KB
#include <algorithm>
#include <iostream>
#include <assert.h>
#include <stdio.h>
#include <iomanip>
#include <utility>
#include <math.h>
#include <time.h>
#include <vector>
#include <set>
#include <map>

#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()

using namespace std;

const int N = 2005;

int n, q, pref[N], suf[N], l, r, sum[N], ans, cn;

string s;

main()
{
    cin >> n >> s;

    s = ' ' + s;

    for (int i = 1; i <= n; i++)
        pref[i] = (s[i] == 'C' ? 1 : -1) + pref[i - 1];

    for (int i = n; i >= 1; i--)
        suf[i] = (s[i] == 'C' ? 1 : -1) + suf[i + 1];

    cin >> q;

    while (q--)
    {
        cn = 0;
        ans = 0;
        for (int i = 1; i<= n; i++)
            sum[i] = 0;

        scanf("%d%d", &l, &r);

        for (int i = l; i <= r; i++)
        {
            if ( pref[i] + cn < pref[l - 1] )
            {
                cn++;
                sum[l] += 1;
                sum[i + 1] -= 1;
                ans++;
            }
        }
        for (int i = 1; i<= n; i++)
            sum[i] += sum[i - 1];

        cn = 0;

        for (int i = r; i >= l; i--)
            cn = min( sum[i] + suf[i] - suf[r + 1], cn );

        printf("%d\n", abs(cn) + ans );

//        system("pause");
    }
}

Compilation message

election.cpp:28:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
election.cpp: In function 'int main()':
election.cpp:49:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &l, &r);
         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 19 ms 248 KB Output is correct
2 Correct 17 ms 356 KB Output is correct
3 Correct 17 ms 448 KB Output is correct
4 Correct 20 ms 448 KB Output is correct
5 Correct 24 ms 540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 248 KB Output is correct
2 Correct 17 ms 356 KB Output is correct
3 Correct 17 ms 448 KB Output is correct
4 Correct 20 ms 448 KB Output is correct
5 Correct 24 ms 540 KB Output is correct
6 Runtime error 5 ms 1240 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 248 KB Output is correct
2 Correct 17 ms 356 KB Output is correct
3 Correct 17 ms 448 KB Output is correct
4 Correct 20 ms 448 KB Output is correct
5 Correct 24 ms 540 KB Output is correct
6 Runtime error 5 ms 1240 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Halted 0 ms 0 KB -