Submission #169242

# Submission time Handle Problem Language Result Execution time Memory
169242 2019-12-19T08:20:09 Z Ruxandra985 Election (BOI18_election) C++14
28 / 100
3000 ms 1936 KB
#include <bits/stdc++.h>

using namespace std;
int v[100010],w[100010];
int main()
{
    FILE *fin = stdin;
    FILE *fout = stdout;
    int n, q , i , change , sum , l , r;
    char c;
    fscanf (fin,"%d\n",&n);
    for (i=1;i<=n;i++){
        c=fgetc (fin);
        if (c == 'C')
            v[i] = 1;
        else v[i] = -1;
        w[i] = v[i];
    }
    fscanf (fin,"%d",&q);
    for (;q;q--){
        fscanf (fin,"%d%d",&l,&r);
        for (i=1;i<=n;i++)
            v[i] = w[i];
        sum = 0;
        change = 0;
        for (i=l;i<=r;i++){
            sum+=v[i];
            if (sum<0){
                v[i] = 0;
                sum++;
                change++;
            }
        }
        sum = 0;
        for (i=r;i>=l;i--){
            sum+=v[i];
            if (sum<0){
                v[i] = 0;
                sum++;
                change++;
            }
        }
        fprintf (fout,"%d\n",change);
    }
    return 0;
}

Compilation message

election.cpp: In function 'int main()':
election.cpp:11:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf (fin,"%d\n",&n);
     ~~~~~~~^~~~~~~~~~~~~~~
election.cpp:19:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf (fin,"%d",&q);
     ~~~~~~~^~~~~~~~~~~~~
election.cpp:21:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         fscanf (fin,"%d%d",&l,&r);
         ~~~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 7 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 8 ms 376 KB Output is correct
5 Correct 7 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 7 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 8 ms 376 KB Output is correct
5 Correct 7 ms 504 KB Output is correct
6 Execution timed out 3049 ms 1936 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 7 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 8 ms 376 KB Output is correct
5 Correct 7 ms 504 KB Output is correct
6 Execution timed out 3049 ms 1936 KB Time limit exceeded
7 Halted 0 ms 0 KB -