답안 #899930

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
899930 2024-01-07T10:20:09 Z PoPularPlusPlus 벽 칠하기 (APIO20_paint) C++17
12 / 100
50 ms 16992 KB
#include "paint.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) x.begin(),x.end()
#define vf first 
#define vs second
const int mod = 1000000007;

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

vector<int> merge(vector<int>& a , vector<int>& b , int add , int m){
	if(a.size() == 0 || b.size() == 0)return {};
	int j = 0;
	int start = 0;
	vector<int> res;
	for(int tp = a.size()-1; tp >= 0; tp--){
		if(a[tp] + add < m){
			break;
		}
		start = tp;
	}
	while(j < b.size() && b[j] < ((a[start] + add)%m))j++;
	if(b[j] == ((a[start] + add)%m))res.pb(a[start]);
	for(int i = (start + 1)%a.size(); i != start && j < b.size(); i=((i + 1)%a.size())){
		while(j < b.size() && b[j] < ((a[i] + add)%m))j++;
		if(b[j] == ((a[i] + add)%m))res.pb(a[i]);
	}
	return res;
}

int minimumInstructions(int n , int m , int k , vector<int> final , vector<int> siz , vector<vector<int>> like){
	bool pos[n];
	memset(pos,0,sizeof pos);

	vector<int> painter[k + 1];

	for(int i = 0; i < m; i++){
		for(int j = 0; j < siz[i]; j++){
			painter[like[i][j]].pb(i);
		}
	}

	vector<int> start_points[n];

	int l = 0;
	while(l < n){
		int r = l + m-1;
		if(r > n-1)break;
		r = min(r , n-1);
		vector<int> valid;
		for(int i : painter[final[r]]){
			valid.pb(i);
		}
		start_points[r] = valid;
		for(int j = r - 1; j >= l; j--){
			vector<int> temp;
			for(int i : painter[final[j]]){
				temp.pb(i);
			}
			valid = merge(temp,valid,1,m);
			start_points[j] = valid;
		}

		if(valid.size()){
			pos[l] = 1;
		}

		if(r == n-1)break;

		vector<int> cur;

		for(int i : painter[final[r+1]]){
			cur.pb(i);
		}

		int add = m;

		for(int i = l + 1; i <= r; i++){
			if(i + m -1 >= n)break;
			add--;
			vector<int> temp;
			for(int j : painter[final[i+m-1]]){
				temp.pb(j);
			}
			cur = merge(cur,temp,i-(l+1),m);
			if(merge(start_points[i],cur,add,m).size()){
				pos[i] = 1;
			}
		}
		if(r + m < n){
			vector<int> temp;
			for(int j : painter[final[r+m]]){
				temp.pb(j);
			}
			pos[r+1] = merge(cur,temp,m-1,m).size() > 0;
			l = r + 2;
		}
		else break;
	}

	int ans = 0;
	vector<int> sp;
	for(int i = 0; i < n-(m-1); i++){
		if(pos[i] == 1){
			///cout << i << ' ';
			sp.pb(i);
		}
	}
	int r = 0;
	for(int i = 0; i < sp.size() && r < n; i++){
		if(sp[i] > r)return -1;
		if(i + 1 < sp.size() && sp[i+1] <= r)continue;
		ans++;
		r = sp[i] + m;
	}
	if(r < n)return -1;
	return ans;
}

Compilation message

paint.cpp: In function 'std::vector<int> merge(std::vector<int>&, std::vector<int>&, int, int)':
paint.cpp:25:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |  while(j < b.size() && b[j] < ((a[start] + add)%m))j++;
      |        ~~^~~~~~~~~~
paint.cpp:27:52: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |  for(int i = (start + 1)%a.size(); i != start && j < b.size(); i=((i + 1)%a.size())){
      |                                                  ~~^~~~~~~~~~
paint.cpp:28:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |   while(j < b.size() && b[j] < ((a[i] + add)%m))j++;
      |         ~~^~~~~~~~~~
paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:113:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  113 |  for(int i = 0; i < sp.size() && r < n; i++){
      |                 ~~^~~~~~~~~~~
paint.cpp:115:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |   if(i + 1 < sp.size() && sp[i+1] <= r)continue;
      |      ~~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 456 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 2 ms 2652 KB Output is correct
14 Correct 2 ms 2648 KB Output is correct
15 Correct 2 ms 2652 KB Output is correct
16 Correct 2 ms 2652 KB Output is correct
17 Correct 2 ms 2652 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 2 ms 2652 KB Output is correct
20 Correct 2 ms 2652 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 15 ms 6672 KB Output is correct
23 Correct 14 ms 6492 KB Output is correct
24 Correct 15 ms 6492 KB Output is correct
25 Correct 3 ms 1372 KB Output is correct
26 Correct 3 ms 1372 KB Output is correct
27 Correct 4 ms 1372 KB Output is correct
28 Correct 4 ms 1116 KB Output is correct
29 Correct 3 ms 1116 KB Output is correct
30 Correct 3 ms 1112 KB Output is correct
31 Correct 10 ms 4952 KB Output is correct
32 Correct 10 ms 4956 KB Output is correct
33 Correct 10 ms 5024 KB Output is correct
34 Correct 10 ms 4956 KB Output is correct
35 Correct 10 ms 4956 KB Output is correct
36 Correct 10 ms 4956 KB Output is correct
37 Correct 19 ms 7312 KB Output is correct
38 Correct 18 ms 7260 KB Output is correct
39 Correct 18 ms 7256 KB Output is correct
40 Correct 13 ms 5340 KB Output is correct
41 Correct 8 ms 3420 KB Output is correct
42 Correct 17 ms 5468 KB Output is correct
43 Correct 11 ms 3160 KB Output is correct
44 Correct 13 ms 2652 KB Output is correct
45 Correct 15 ms 4184 KB Output is correct
46 Correct 38 ms 15708 KB Output is correct
47 Correct 26 ms 10588 KB Output is correct
48 Correct 28 ms 12628 KB Output is correct
49 Correct 30 ms 11460 KB Output is correct
50 Correct 32 ms 11348 KB Output is correct
51 Correct 27 ms 8796 KB Output is correct
52 Correct 14 ms 5852 KB Output is correct
53 Correct 17 ms 5704 KB Output is correct
54 Correct 18 ms 5468 KB Output is correct
55 Correct 16 ms 4700 KB Output is correct
56 Correct 15 ms 4444 KB Output is correct
57 Correct 15 ms 4188 KB Output is correct
58 Correct 43 ms 16856 KB Output is correct
59 Correct 43 ms 16948 KB Output is correct
60 Correct 43 ms 16932 KB Output is correct
61 Correct 44 ms 16848 KB Output is correct
62 Correct 50 ms 16992 KB Output is correct
63 Correct 44 ms 16904 KB Output is correct
64 Correct 41 ms 14172 KB Output is correct
65 Correct 42 ms 14216 KB Output is correct
66 Correct 41 ms 14160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 456 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 2 ms 2652 KB Output is correct
14 Correct 2 ms 2648 KB Output is correct
15 Correct 2 ms 2652 KB Output is correct
16 Correct 2 ms 2652 KB Output is correct
17 Correct 2 ms 2652 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 2 ms 2652 KB Output is correct
20 Correct 2 ms 2652 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 396 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Incorrect 1 ms 348 KB Output isn't correct
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 456 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 2 ms 2652 KB Output is correct
16 Correct 2 ms 2648 KB Output is correct
17 Correct 2 ms 2652 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 2 ms 2652 KB Output is correct
20 Correct 2 ms 2652 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 2 ms 2652 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 15 ms 6672 KB Output is correct
25 Correct 14 ms 6492 KB Output is correct
26 Correct 15 ms 6492 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 396 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Incorrect 1 ms 348 KB Output isn't correct
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 456 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 2 ms 2652 KB Output is correct
16 Correct 2 ms 2648 KB Output is correct
17 Correct 2 ms 2652 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 2 ms 2652 KB Output is correct
20 Correct 2 ms 2652 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 2 ms 2652 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 15 ms 6672 KB Output is correct
25 Correct 14 ms 6492 KB Output is correct
26 Correct 15 ms 6492 KB Output is correct
27 Correct 3 ms 1372 KB Output is correct
28 Correct 3 ms 1372 KB Output is correct
29 Correct 4 ms 1372 KB Output is correct
30 Correct 4 ms 1116 KB Output is correct
31 Correct 3 ms 1116 KB Output is correct
32 Correct 3 ms 1112 KB Output is correct
33 Correct 10 ms 4952 KB Output is correct
34 Correct 10 ms 4956 KB Output is correct
35 Correct 10 ms 5024 KB Output is correct
36 Correct 10 ms 4956 KB Output is correct
37 Correct 10 ms 4956 KB Output is correct
38 Correct 10 ms 4956 KB Output is correct
39 Correct 19 ms 7312 KB Output is correct
40 Correct 18 ms 7260 KB Output is correct
41 Correct 18 ms 7256 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 396 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Incorrect 1 ms 348 KB Output isn't correct
47 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 456 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 2 ms 2652 KB Output is correct
16 Correct 2 ms 2648 KB Output is correct
17 Correct 2 ms 2652 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 2 ms 2652 KB Output is correct
20 Correct 2 ms 2652 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 2 ms 2652 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 15 ms 6672 KB Output is correct
25 Correct 14 ms 6492 KB Output is correct
26 Correct 15 ms 6492 KB Output is correct
27 Correct 3 ms 1372 KB Output is correct
28 Correct 3 ms 1372 KB Output is correct
29 Correct 4 ms 1372 KB Output is correct
30 Correct 4 ms 1116 KB Output is correct
31 Correct 3 ms 1116 KB Output is correct
32 Correct 3 ms 1112 KB Output is correct
33 Correct 10 ms 4952 KB Output is correct
34 Correct 10 ms 4956 KB Output is correct
35 Correct 10 ms 5024 KB Output is correct
36 Correct 10 ms 4956 KB Output is correct
37 Correct 10 ms 4956 KB Output is correct
38 Correct 10 ms 4956 KB Output is correct
39 Correct 19 ms 7312 KB Output is correct
40 Correct 18 ms 7260 KB Output is correct
41 Correct 18 ms 7256 KB Output is correct
42 Correct 13 ms 5340 KB Output is correct
43 Correct 8 ms 3420 KB Output is correct
44 Correct 17 ms 5468 KB Output is correct
45 Correct 11 ms 3160 KB Output is correct
46 Correct 13 ms 2652 KB Output is correct
47 Correct 15 ms 4184 KB Output is correct
48 Correct 38 ms 15708 KB Output is correct
49 Correct 26 ms 10588 KB Output is correct
50 Correct 28 ms 12628 KB Output is correct
51 Correct 30 ms 11460 KB Output is correct
52 Correct 32 ms 11348 KB Output is correct
53 Correct 27 ms 8796 KB Output is correct
54 Correct 14 ms 5852 KB Output is correct
55 Correct 17 ms 5704 KB Output is correct
56 Correct 18 ms 5468 KB Output is correct
57 Correct 16 ms 4700 KB Output is correct
58 Correct 15 ms 4444 KB Output is correct
59 Correct 15 ms 4188 KB Output is correct
60 Correct 43 ms 16856 KB Output is correct
61 Correct 43 ms 16948 KB Output is correct
62 Correct 43 ms 16932 KB Output is correct
63 Correct 44 ms 16848 KB Output is correct
64 Correct 50 ms 16992 KB Output is correct
65 Correct 44 ms 16904 KB Output is correct
66 Correct 41 ms 14172 KB Output is correct
67 Correct 42 ms 14216 KB Output is correct
68 Correct 41 ms 14160 KB Output is correct
69 Correct 0 ms 348 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
71 Correct 0 ms 396 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Incorrect 1 ms 348 KB Output isn't correct
74 Halted 0 ms 0 KB -