답안 #68299

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
68299 2018-08-16T12:16:30 Z Bruteforceman Election (BOI18_election) C++11
28 / 100
3000 ms 2872 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;
	int mn = 0;
	for(int i = l; i <= r; i++) {
		cur += a[i];
		mn = min(mn, cur);
		mx = max(mx, cur - mn);
	}
	ans -= mn;
	ans += mx - (cur - mn);
	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;
}
// CCCTTTTTTCC
// CCCTTTCC 

Compilation message

election.cpp: In function 'int main(int, const char**)':
election.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
election.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s", s);
  ~~~~~^~~~~~~~~
election.cpp:31:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &q);
  ~~~~~^~~~~~~~~~
election.cpp:34: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 376 KB Output is correct
3 Correct 6 ms 516 KB Output is correct
4 Correct 5 ms 540 KB Output is correct
5 Correct 6 ms 568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 6 ms 516 KB Output is correct
4 Correct 5 ms 540 KB Output is correct
5 Correct 6 ms 568 KB Output is correct
6 Correct 1844 ms 2356 KB Output is correct
7 Execution timed out 3047 ms 2872 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 376 KB Output is correct
3 Correct 6 ms 516 KB Output is correct
4 Correct 5 ms 540 KB Output is correct
5 Correct 6 ms 568 KB Output is correct
6 Correct 1844 ms 2356 KB Output is correct
7 Execution timed out 3047 ms 2872 KB Time limit exceeded
8 Halted 0 ms 0 KB -