Submission #417639

# Submission time Handle Problem Language Result Execution time Memory
417639 2021-06-04T05:07:52 Z 송준혁(#7519) Parking Problem (innopolis2021_final_A) C++17
100 / 100
195 ms 1648 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define lb lower_bound
#define MOD 1000000007
#define INF (1ll<<62)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

int N, M, TC;
int A[101010];
char S[101010];

struct Block{
	int x;
	bool operator<(const Block &r)const{
		if (r.x == 1) return false;
		if (x == 1) return true;
		if ((x+r.x)&1) return r.x&1;
		return x < r.x;
	}
};

priority_queue<Block> PQ;

int main(){
	scanf("%d", &TC);
	while (TC--){
		int c=0;
		scanf("%s", S+1);
		M=0;
		for (int i=1; S[i]; i++){
			if (S[i] == 'X'){
				if (c > 1) A[++M] = c-1;
				c=0;
			}
			else c++;
		}
		if (c > 1) A[++M] = c-1;
		scanf("%s", S+1);
		N = strlen(S+1);
		int ans=-1, lo=0, hi=N;
		while (lo<=hi){
			int m=lo+hi>>1;
			int a=0, b=0;
			for (int i=1; i<=m; i++){
				if (S[i] == 'M') b++;
				else a++;
			}
			while (PQ.size()) PQ.pop();
			for (int i=1; i<=M; i++) PQ.push((Block){A[i]});
			while (a && PQ.size()){
				Block t = PQ.top(); PQ.pop();
				a--;
				if (t.x > 3) PQ.push((Block){t.x-3});
			}
			while (b && PQ.size()){
				Block t = PQ.top(); PQ.pop();
				b--;
				if (t.x > 2) PQ.push((Block){t.x-2});
			}
			if (!PQ.size()) hi=m-1;
			else ans=m, lo=m+1;
		}
		for (int i=0; i<=N; i++) printf("%c", (i<=ans)?'Y':'N');
		puts("\n");
	}
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:46:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   46 |    int m=lo+hi>>1;
      |          ~~^~~
Main.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |  scanf("%d", &TC);
      |  ~~~~~^~~~~~~~~~~
Main.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |   scanf("%s", S+1);
      |   ~~~~~^~~~~~~~~~~
Main.cpp:42:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |   scanf("%s", S+1);
      |   ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 36 ms 536 KB Output is correct
2 Correct 32 ms 656 KB Output is correct
3 Correct 41 ms 620 KB Output is correct
4 Correct 50 ms 668 KB Output is correct
5 Correct 29 ms 452 KB Output is correct
6 Correct 51 ms 684 KB Output is correct
7 Correct 29 ms 436 KB Output is correct
8 Correct 42 ms 612 KB Output is correct
9 Correct 40 ms 532 KB Output is correct
10 Correct 30 ms 504 KB Output is correct
11 Correct 41 ms 580 KB Output is correct
12 Correct 36 ms 560 KB Output is correct
13 Correct 28 ms 488 KB Output is correct
14 Correct 42 ms 612 KB Output is correct
15 Correct 30 ms 584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 564 KB Output is correct
2 Correct 36 ms 476 KB Output is correct
3 Correct 44 ms 696 KB Output is correct
4 Correct 58 ms 580 KB Output is correct
5 Correct 36 ms 668 KB Output is correct
6 Correct 45 ms 504 KB Output is correct
7 Correct 36 ms 444 KB Output is correct
8 Correct 45 ms 580 KB Output is correct
9 Correct 59 ms 1364 KB Output is correct
10 Correct 38 ms 1208 KB Output is correct
11 Correct 47 ms 1536 KB Output is correct
12 Correct 51 ms 1348 KB Output is correct
13 Correct 33 ms 1228 KB Output is correct
14 Correct 45 ms 1472 KB Output is correct
15 Correct 32 ms 1080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 195 ms 792 KB Output is correct
2 Correct 133 ms 496 KB Output is correct
3 Correct 85 ms 452 KB Output is correct
4 Correct 51 ms 544 KB Output is correct
5 Correct 45 ms 556 KB Output is correct
6 Correct 42 ms 588 KB Output is correct
7 Correct 42 ms 648 KB Output is correct
8 Correct 44 ms 576 KB Output is correct
9 Correct 30 ms 552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 536 KB Output is correct
2 Correct 32 ms 656 KB Output is correct
3 Correct 41 ms 620 KB Output is correct
4 Correct 50 ms 668 KB Output is correct
5 Correct 29 ms 452 KB Output is correct
6 Correct 51 ms 684 KB Output is correct
7 Correct 29 ms 436 KB Output is correct
8 Correct 42 ms 612 KB Output is correct
9 Correct 40 ms 532 KB Output is correct
10 Correct 30 ms 504 KB Output is correct
11 Correct 41 ms 580 KB Output is correct
12 Correct 36 ms 560 KB Output is correct
13 Correct 28 ms 488 KB Output is correct
14 Correct 42 ms 612 KB Output is correct
15 Correct 30 ms 584 KB Output is correct
16 Correct 52 ms 564 KB Output is correct
17 Correct 36 ms 476 KB Output is correct
18 Correct 44 ms 696 KB Output is correct
19 Correct 58 ms 580 KB Output is correct
20 Correct 36 ms 668 KB Output is correct
21 Correct 45 ms 504 KB Output is correct
22 Correct 36 ms 444 KB Output is correct
23 Correct 45 ms 580 KB Output is correct
24 Correct 59 ms 1364 KB Output is correct
25 Correct 38 ms 1208 KB Output is correct
26 Correct 47 ms 1536 KB Output is correct
27 Correct 51 ms 1348 KB Output is correct
28 Correct 33 ms 1228 KB Output is correct
29 Correct 45 ms 1472 KB Output is correct
30 Correct 32 ms 1080 KB Output is correct
31 Correct 195 ms 792 KB Output is correct
32 Correct 133 ms 496 KB Output is correct
33 Correct 85 ms 452 KB Output is correct
34 Correct 51 ms 544 KB Output is correct
35 Correct 45 ms 556 KB Output is correct
36 Correct 42 ms 588 KB Output is correct
37 Correct 42 ms 648 KB Output is correct
38 Correct 44 ms 576 KB Output is correct
39 Correct 30 ms 552 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 8 ms 460 KB Output is correct
44 Correct 6 ms 332 KB Output is correct
45 Correct 4 ms 332 KB Output is correct
46 Correct 30 ms 1116 KB Output is correct
47 Correct 163 ms 1648 KB Output is correct
48 Correct 155 ms 1576 KB Output is correct
49 Correct 183 ms 1300 KB Output is correct