답안 #55411

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
55411 2018-07-07T08:26:22 Z 김세빈(#1545) Toilets (JOI16_toilets) C++11
36 / 100
78 ms 892 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

char str[202020];
ll n, k, f, m;

bool check(ll k)
{
	ll i, a, b, s;
	
	a = b = 0;
	
	for(i=n+n-1;i>=0;i--){
		if(str[i] == 'M'){
			if(k) k --;
			else a ++;
		}
		else b ++;
		if((~(a+b) & 1) && a > b) return 0;
	}
	
	return 1;
}

int main()
{
	ll i, s, e;
	
	scanf("%lld%lld", &n, &k);
	
	if(k > 1) return 0;
	
	scanf("%s", str);
	
	for(i=0;i<n+n;i++){
		if(str[i] == 'F') f ++;
		else m ++;
	}
	
	if(f < m){
		printf("-1\n");
		return 0;
	}
	
	for(s=0,e=n+n;s<=e;){
		if(check(s+e>>1)) e = (s+e>>1) - 1;
		else s = (s+e>>1) + 1;
	}
	
	printf("%lld\n", e + 1);
	
	return 0;
}

Compilation message

toilets.cpp: In function 'bool check(ll)':
toilets.cpp:12:14: warning: unused variable 's' [-Wunused-variable]
  ll i, a, b, s;
              ^
toilets.cpp: In function 'int main()':
toilets.cpp:49:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   if(check(s+e>>1)) e = (s+e>>1) - 1;
            ~^~
toilets.cpp:49:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   if(check(s+e>>1)) e = (s+e>>1) - 1;
                          ~^~
toilets.cpp:50:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   else s = (s+e>>1) + 1;
             ~^~
toilets.cpp:32:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld", &n, &k);
  ~~~~~^~~~~~~~~~~~~~~~~~~~
toilets.cpp:36:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s", str);
  ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 428 KB Output is correct
4 Correct 3 ms 496 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 3 ms 544 KB Output is correct
7 Correct 3 ms 544 KB Output is correct
8 Correct 2 ms 544 KB Output is correct
9 Correct 2 ms 544 KB Output is correct
10 Correct 4 ms 544 KB Output is correct
11 Correct 2 ms 544 KB Output is correct
12 Correct 3 ms 544 KB Output is correct
13 Correct 3 ms 544 KB Output is correct
14 Correct 2 ms 544 KB Output is correct
15 Correct 2 ms 628 KB Output is correct
16 Correct 2 ms 628 KB Output is correct
17 Correct 2 ms 628 KB Output is correct
18 Correct 2 ms 628 KB Output is correct
19 Correct 2 ms 628 KB Output is correct
20 Correct 2 ms 628 KB Output is correct
21 Correct 2 ms 628 KB Output is correct
22 Correct 2 ms 628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 428 KB Output is correct
4 Correct 3 ms 496 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 3 ms 544 KB Output is correct
7 Correct 3 ms 544 KB Output is correct
8 Correct 2 ms 544 KB Output is correct
9 Correct 2 ms 544 KB Output is correct
10 Correct 4 ms 544 KB Output is correct
11 Correct 2 ms 544 KB Output is correct
12 Correct 3 ms 544 KB Output is correct
13 Correct 3 ms 544 KB Output is correct
14 Correct 2 ms 544 KB Output is correct
15 Correct 2 ms 628 KB Output is correct
16 Correct 2 ms 628 KB Output is correct
17 Correct 2 ms 628 KB Output is correct
18 Correct 2 ms 628 KB Output is correct
19 Correct 2 ms 628 KB Output is correct
20 Correct 2 ms 628 KB Output is correct
21 Correct 2 ms 628 KB Output is correct
22 Correct 2 ms 628 KB Output is correct
23 Correct 19 ms 764 KB Output is correct
24 Correct 25 ms 764 KB Output is correct
25 Correct 23 ms 764 KB Output is correct
26 Correct 10 ms 764 KB Output is correct
27 Correct 5 ms 764 KB Output is correct
28 Correct 26 ms 764 KB Output is correct
29 Correct 24 ms 776 KB Output is correct
30 Correct 78 ms 776 KB Output is correct
31 Correct 27 ms 776 KB Output is correct
32 Correct 23 ms 776 KB Output is correct
33 Correct 4 ms 776 KB Output is correct
34 Correct 15 ms 776 KB Output is correct
35 Correct 22 ms 776 KB Output is correct
36 Correct 27 ms 776 KB Output is correct
37 Correct 11 ms 776 KB Output is correct
38 Correct 6 ms 776 KB Output is correct
39 Correct 21 ms 776 KB Output is correct
40 Correct 16 ms 892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 428 KB Output is correct
4 Correct 3 ms 496 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 3 ms 544 KB Output is correct
7 Correct 3 ms 544 KB Output is correct
8 Correct 2 ms 544 KB Output is correct
9 Correct 2 ms 544 KB Output is correct
10 Correct 4 ms 544 KB Output is correct
11 Correct 2 ms 544 KB Output is correct
12 Correct 3 ms 544 KB Output is correct
13 Correct 3 ms 544 KB Output is correct
14 Correct 2 ms 544 KB Output is correct
15 Correct 2 ms 628 KB Output is correct
16 Correct 2 ms 628 KB Output is correct
17 Correct 2 ms 628 KB Output is correct
18 Correct 2 ms 628 KB Output is correct
19 Correct 2 ms 628 KB Output is correct
20 Correct 2 ms 628 KB Output is correct
21 Correct 2 ms 628 KB Output is correct
22 Correct 2 ms 628 KB Output is correct
23 Correct 19 ms 764 KB Output is correct
24 Correct 25 ms 764 KB Output is correct
25 Correct 23 ms 764 KB Output is correct
26 Correct 10 ms 764 KB Output is correct
27 Correct 5 ms 764 KB Output is correct
28 Correct 26 ms 764 KB Output is correct
29 Correct 24 ms 776 KB Output is correct
30 Correct 78 ms 776 KB Output is correct
31 Correct 27 ms 776 KB Output is correct
32 Correct 23 ms 776 KB Output is correct
33 Correct 4 ms 776 KB Output is correct
34 Correct 15 ms 776 KB Output is correct
35 Correct 22 ms 776 KB Output is correct
36 Correct 27 ms 776 KB Output is correct
37 Correct 11 ms 776 KB Output is correct
38 Correct 6 ms 776 KB Output is correct
39 Correct 21 ms 776 KB Output is correct
40 Correct 16 ms 892 KB Output is correct
41 Incorrect 2 ms 892 KB Output isn't correct
42 Halted 0 ms 0 KB -