Submission #61609

# Submission time Handle Problem Language Result Execution time Memory
61609 2018-07-26T08:04:27 Z 김세빈(#1779) Election (BOI18_election) C++11
28 / 100
3000 ms 1508 KB
#include <bits/stdc++.h>

using namespace std;

char str[505050];
int K[505050], S[505050], L[505050];
bool chk[505050];
int n;

int main()
{
	int q, i, l, r, k, s, minv, maxv;
	
	scanf("%d%s%d", &n, str, &q);
	
	s = 0; S[++s] = 0;
	
	for(i=1; i<=n; i++){
		if(str[i-1] == 'C') S[i] = S[i-1] + 1;
		else S[i] = S[i-1] - 1;
		
		for(; s && S[K[s]] > S[i]; s--);
		if(s) L[i] = K[s];
		else L[i] = -1;
		K[++s] = i;
	}
	
	for(; q--; ){
		scanf("%d%d", &l, &r);
		
		k = 0;
		
		for(i=l; i<=r; i++){
			if(str[i-1] == 'T' && L[i] < l - 1){
				k ++, chk[i] = 1;
			}
		}
		
		s = maxv = 0;
		
		for(i=r; i>=l; i--){
			if(str[i-1] == 'C') s ++;
			else s -= !chk[i];
			
			maxv = max(maxv, -s);
			chk[i] = 0;
		}
		
		printf("%d\n", k + maxv);
	}
	
	return 0;
}

Compilation message

election.cpp: In function 'int main()':
election.cpp:12:24: warning: unused variable 'minv' [-Wunused-variable]
  int q, i, l, r, k, s, minv, maxv;
                        ^~~~
election.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%s%d", &n, str, &q);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
election.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &l, &r);
   ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 376 KB Output is correct
2 Correct 14 ms 548 KB Output is correct
3 Correct 13 ms 548 KB Output is correct
4 Correct 9 ms 548 KB Output is correct
5 Correct 7 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 376 KB Output is correct
2 Correct 14 ms 548 KB Output is correct
3 Correct 13 ms 548 KB Output is correct
4 Correct 9 ms 548 KB Output is correct
5 Correct 7 ms 632 KB Output is correct
6 Execution timed out 3095 ms 1508 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 376 KB Output is correct
2 Correct 14 ms 548 KB Output is correct
3 Correct 13 ms 548 KB Output is correct
4 Correct 9 ms 548 KB Output is correct
5 Correct 7 ms 632 KB Output is correct
6 Execution timed out 3095 ms 1508 KB Time limit exceeded
7 Halted 0 ms 0 KB -