제출 #1367126

#제출 시각아이디문제언어결과실행 시간메모리
1367126matthewElection (BOI18_election)C++20
0 / 100
1 ms344 KiB
#include <stdio.h>
#include <ctype.h>
#include <algorithm>
using ll = long long;

const int MAX_N = 500'000;
const int INF = 1e9;
char a[MAX_N];
int s[MAX_N + 1];

char next_char() {
  char ch;
  while(isspace(ch = fgetc(stdin)));
  return ch;
}

int main() {
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif

  int n;
  scanf("%d", &n);
  for(int i = 0; i < n; i++) {
    a[i] = next_char();
  }

  s[0] = 0;
  for(int i = 1; i <= n; i++) {
    s[i] = s[i - 1] + (a[i - 1] == 'C' ? 1 : -1);
  }

  int q;
  scanf("%d", &q);
  for(int i = 0; i < q; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    int min = INF;
    int max = -INF;
    for(int j = l; j <= r; j++) {
      min = std::min(min, s[j]);
      max = std::max(max, s[j]);
    }
    min -= s[l - 1];
    max -= s[l - 1];
    printf("%d\n", std::max(0, std::max(-min, max - s[r])));
  }

  return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

election.cpp: In function 'int main()':
election.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
election.cpp:34:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |   scanf("%d", &q);
      |   ~~~~~^~~~~~~~~~
election.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     scanf("%d%d", &l, &r);
      |     ~~~~~^~~~~~~~~~~~~~~~
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…