답안 #489588

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
489588 2021-11-23T10:09:55 Z pliam Election (BOI18_election) C++14
28 / 100
6 ms 332 KB
#include <bits/stdc++.h>
#define MAXN 5000
using namespace std;

int N,Q,a[MAXN],b[MAXN];

int main(){
    scanf("%d",&N);
    for(int i=0;i<N;i++){
        char c;
        scanf(" %c",&c);
        a[i]=(c=='C')?1:-1;
    }
    scanf("%d",&Q);
    for(int i=0;i<Q;i++){
        int l,r;
        scanf("%d %d",&l,&r);
        l--; r--;
        int sum=0,countb=0;
        for(int pos=l;pos<=r;pos++){
            b[pos]=0;
            sum+=a[pos];
            if(sum<0){
                b[pos]--;
                sum=0;
                countb++;
            }
        }
        sum=0;
        for(int pos=r;pos>=l;pos--){
            sum+=a[pos];
            if(sum<0){
                b[pos]++;
                sum=0;
            }
        }
        sum=0;
        for(int pos=l;pos<=r;pos++){
            sum+=b[pos];
            if(sum<0) sum=0;
        }
        printf("%d\n",countb+sum);
    }
}

Compilation message

election.cpp: In function 'int main()':
election.cpp:8:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |     scanf("%d",&N);
      |     ~~~~~^~~~~~~~~
election.cpp:11:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |         scanf(" %c",&c);
      |         ~~~~~^~~~~~~~~~
election.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     scanf("%d",&Q);
      |     ~~~~~^~~~~~~~~
election.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         scanf("%d %d",&l,&r);
      |         ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 332 KB Output is correct
2 Correct 4 ms 332 KB Output is correct
3 Correct 4 ms 332 KB Output is correct
4 Correct 6 ms 332 KB Output is correct
5 Correct 5 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 332 KB Output is correct
2 Correct 4 ms 332 KB Output is correct
3 Correct 4 ms 332 KB Output is correct
4 Correct 6 ms 332 KB Output is correct
5 Correct 5 ms 308 KB Output is correct
6 Incorrect 1 ms 332 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 332 KB Output is correct
2 Correct 4 ms 332 KB Output is correct
3 Correct 4 ms 332 KB Output is correct
4 Correct 6 ms 332 KB Output is correct
5 Correct 5 ms 308 KB Output is correct
6 Incorrect 1 ms 332 KB Output isn't correct
7 Halted 0 ms 0 KB -