Submission #103536

# Submission time Handle Problem Language Result Execution time Memory
103536 2019-03-31T10:53:31 Z ekrem Election (BOI18_election) C++
28 / 100
3000 ms 1520 KB
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define N 1000005
using namespace std;

typedef long long ll;

int n, q, bas, son, say, ans, u[N];
char s[N];

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%d %s %d",&n ,s + 1 ,&q);
	while(q--){
		scanf("%d %d",&bas, &son);
		ans = say = 0;
		for(int i = bas; i <= son; i++){
			if(s[i] == 'C')
				say++;
			else
				say--;
			if(say < 0){
				ans++;
				say = 0;
				u[i] = 1;
			} else
				u[i] = 0;
		}
		say = 0;
		for(int i = son; i >= bas; i--){
			if(u[i])
				continue;
			if(s[i] == 'C')
				say++;
			else
				say--;
			if(say < 0){
				say = 0;
				ans++;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Compilation message

election.cpp: In function 'int main()':
election.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %s %d",&n ,s + 1 ,&q);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
election.cpp:20:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&bas, &son);
   ~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 384 KB Output is correct
2 Correct 10 ms 384 KB Output is correct
3 Correct 7 ms 384 KB Output is correct
4 Correct 9 ms 384 KB Output is correct
5 Correct 8 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 384 KB Output is correct
2 Correct 10 ms 384 KB Output is correct
3 Correct 7 ms 384 KB Output is correct
4 Correct 9 ms 384 KB Output is correct
5 Correct 8 ms 384 KB Output is correct
6 Execution timed out 3032 ms 1520 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 384 KB Output is correct
2 Correct 10 ms 384 KB Output is correct
3 Correct 7 ms 384 KB Output is correct
4 Correct 9 ms 384 KB Output is correct
5 Correct 8 ms 384 KB Output is correct
6 Execution timed out 3032 ms 1520 KB Time limit exceeded
7 Halted 0 ms 0 KB -