답안 #68257

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
68257 2018-08-16T10:21:50 Z Bruteforceman Election (BOI18_election) C++11
28 / 100
3000 ms 3124 KB
#include "bits/stdc++.h"
using namespace std;
int a[500010];
int p[500010];

int solve(int l, int r) {
	int cur = 0;
	int ans = 0;
	int mx = 0;
	for(int i = l; i <= r; i++) {
		cur += a[i];
		if(cur < 0) {
			++ans;
			cur = 0;
		}
		mx = max(mx, cur);
	}
	ans += mx - cur;
	return ans;
}
char s[500010];

int main(int argc, char const *argv[])
{
	int n;
	scanf("%d", &n);
	scanf("%s", s);
	for(int i = 1; i <= n; i++) {
		a[i] = s[i - 1] == 'C' ? 1 : -1;
	}
	int q;
	scanf("%d", &q);
	while(q--) {
		int l, r;
		scanf("%d %d", &l, &r);
		printf("%d\n", solve(l, r));
	}
	return 0;
}

Compilation message

election.cpp: In function 'int main(int, const char**)':
election.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
election.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s", s);
  ~~~~~^~~~~~~~~
election.cpp:32:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &q);
  ~~~~~^~~~~~~~~~
election.cpp:35:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &l, &r);
   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 492 KB Output is correct
3 Correct 6 ms 604 KB Output is correct
4 Correct 8 ms 604 KB Output is correct
5 Correct 7 ms 688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 492 KB Output is correct
3 Correct 6 ms 604 KB Output is correct
4 Correct 8 ms 604 KB Output is correct
5 Correct 7 ms 688 KB Output is correct
6 Correct 1407 ms 2384 KB Output is correct
7 Execution timed out 3044 ms 3124 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 492 KB Output is correct
3 Correct 6 ms 604 KB Output is correct
4 Correct 8 ms 604 KB Output is correct
5 Correct 7 ms 688 KB Output is correct
6 Correct 1407 ms 2384 KB Output is correct
7 Execution timed out 3044 ms 3124 KB Time limit exceeded
8 Halted 0 ms 0 KB -