답안 #258037

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
258037 2020-08-05T08:40:01 Z 송준혁(#5048) Toilets (JOI16_toilets) C++17
100 / 100
92 ms 7544 KB
#include <bits/stdc++.h>
#define pb push_back
#define lb lower_bound
#define fi first
#define se second
#define mup(a,x) a=min(a,x)
#define Mup(a,x) a=max(a,x)
#define INF 1234567890
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

int M;
LL ans=-1, N, R[101010], P[101010];
char str[202020];
vector<char> S[101010];
vector<int> V;

int main(){
	scanf("%lld %d", &N, &M);
	scanf("%d", &R);
	for (int i=1; i<=M; i++){
		scanf("%s", str);
		for (int j=0; str[j]; j++){
			if (str[j] == 'M') P[i]++;
			S[i].pb(str[j]);
		}
		scanf("%lld", &R[i]);
	}
	LL lo=0, hi=N;
	while (lo<=hi){
		LL m=lo+hi>>1, x=0;
		for (int i=1; i<=M; i++){
			LL a=0, b=0;
			for (int j=0; j<S[i].size(); j++){
				if (S[i][j] == 'F') a--;
				else a++;
				b = min(a, b);
			}
			if (x+b < -m-1){
				x = max(-m-1, a-b-m-1);
				if (a>=0) x += a*(R[i]-1);
			}
			else x += a*R[i];
		}
		if (x > 0) lo = m+1;
		else hi = m-1, ans = m;
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

toilets.cpp: In function 'int main()':
toilets.cpp:21:16: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'LL (*)[101010] {aka long long int (*)[101010]}' [-Wformat=]
  scanf("%d", &R);
              ~~^
toilets.cpp:32:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   LL m=lo+hi>>1, x=0;
        ~~^~~
toilets.cpp:35:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int j=0; j<S[i].size(); j++){
                  ~^~~~~~~~~~~~
toilets.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %d", &N, &M);
  ~~~~~^~~~~~~~~~~~~~~~~~~
toilets.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &R);
  ~~~~~^~~~~~~~~~
toilets.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", str);
   ~~~~~^~~~~~~~~~~
toilets.cpp:28:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &R[i]);
   ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 3 ms 2688 KB Output is correct
9 Correct 3 ms 2688 KB Output is correct
10 Correct 2 ms 2704 KB Output is correct
11 Correct 3 ms 2688 KB Output is correct
12 Correct 3 ms 2688 KB Output is correct
13 Correct 2 ms 2688 KB Output is correct
14 Correct 2 ms 2688 KB Output is correct
15 Correct 2 ms 2688 KB Output is correct
16 Correct 3 ms 2688 KB Output is correct
17 Correct 2 ms 2688 KB Output is correct
18 Correct 2 ms 2688 KB Output is correct
19 Correct 2 ms 2688 KB Output is correct
20 Correct 2 ms 2688 KB Output is correct
21 Correct 2 ms 2688 KB Output is correct
22 Correct 2 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 3 ms 2688 KB Output is correct
9 Correct 3 ms 2688 KB Output is correct
10 Correct 2 ms 2704 KB Output is correct
11 Correct 3 ms 2688 KB Output is correct
12 Correct 3 ms 2688 KB Output is correct
13 Correct 2 ms 2688 KB Output is correct
14 Correct 2 ms 2688 KB Output is correct
15 Correct 2 ms 2688 KB Output is correct
16 Correct 3 ms 2688 KB Output is correct
17 Correct 2 ms 2688 KB Output is correct
18 Correct 2 ms 2688 KB Output is correct
19 Correct 2 ms 2688 KB Output is correct
20 Correct 2 ms 2688 KB Output is correct
21 Correct 2 ms 2688 KB Output is correct
22 Correct 2 ms 2688 KB Output is correct
23 Correct 22 ms 3328 KB Output is correct
24 Correct 29 ms 3328 KB Output is correct
25 Correct 20 ms 3328 KB Output is correct
26 Correct 8 ms 3328 KB Output is correct
27 Correct 8 ms 3328 KB Output is correct
28 Correct 21 ms 3328 KB Output is correct
29 Correct 23 ms 3328 KB Output is correct
30 Correct 17 ms 3328 KB Output is correct
31 Correct 21 ms 3328 KB Output is correct
32 Correct 22 ms 3328 KB Output is correct
33 Correct 11 ms 3328 KB Output is correct
34 Correct 11 ms 3328 KB Output is correct
35 Correct 23 ms 3328 KB Output is correct
36 Correct 24 ms 3328 KB Output is correct
37 Correct 11 ms 3328 KB Output is correct
38 Correct 25 ms 3328 KB Output is correct
39 Correct 22 ms 3328 KB Output is correct
40 Correct 17 ms 3328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 3 ms 2688 KB Output is correct
9 Correct 3 ms 2688 KB Output is correct
10 Correct 2 ms 2704 KB Output is correct
11 Correct 3 ms 2688 KB Output is correct
12 Correct 3 ms 2688 KB Output is correct
13 Correct 2 ms 2688 KB Output is correct
14 Correct 2 ms 2688 KB Output is correct
15 Correct 2 ms 2688 KB Output is correct
16 Correct 3 ms 2688 KB Output is correct
17 Correct 2 ms 2688 KB Output is correct
18 Correct 2 ms 2688 KB Output is correct
19 Correct 2 ms 2688 KB Output is correct
20 Correct 2 ms 2688 KB Output is correct
21 Correct 2 ms 2688 KB Output is correct
22 Correct 2 ms 2688 KB Output is correct
23 Correct 22 ms 3328 KB Output is correct
24 Correct 29 ms 3328 KB Output is correct
25 Correct 20 ms 3328 KB Output is correct
26 Correct 8 ms 3328 KB Output is correct
27 Correct 8 ms 3328 KB Output is correct
28 Correct 21 ms 3328 KB Output is correct
29 Correct 23 ms 3328 KB Output is correct
30 Correct 17 ms 3328 KB Output is correct
31 Correct 21 ms 3328 KB Output is correct
32 Correct 22 ms 3328 KB Output is correct
33 Correct 11 ms 3328 KB Output is correct
34 Correct 11 ms 3328 KB Output is correct
35 Correct 23 ms 3328 KB Output is correct
36 Correct 24 ms 3328 KB Output is correct
37 Correct 11 ms 3328 KB Output is correct
38 Correct 25 ms 3328 KB Output is correct
39 Correct 22 ms 3328 KB Output is correct
40 Correct 17 ms 3328 KB Output is correct
41 Correct 69 ms 7544 KB Output is correct
42 Correct 64 ms 7416 KB Output is correct
43 Correct 2 ms 2688 KB Output is correct
44 Correct 2 ms 2688 KB Output is correct
45 Correct 1 ms 2688 KB Output is correct
46 Correct 79 ms 3448 KB Output is correct
47 Correct 65 ms 3064 KB Output is correct
48 Correct 68 ms 3044 KB Output is correct
49 Correct 39 ms 3068 KB Output is correct
50 Correct 22 ms 3072 KB Output is correct
51 Correct 92 ms 3448 KB Output is correct
52 Correct 64 ms 7432 KB Output is correct
53 Correct 59 ms 7416 KB Output is correct
54 Correct 72 ms 7416 KB Output is correct
55 Correct 21 ms 2944 KB Output is correct
56 Correct 35 ms 2944 KB Output is correct