답안 #899927

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
899927 2024-01-07T10:18:17 Z PoPularPlusPlus 벽 칠하기 (APIO20_paint) C++17
12 / 100
57 ms 18196 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 440 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 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 448 KB Output is correct
13 Correct 3 ms 2652 KB Output is correct
14 Correct 2 ms 2656 KB Output is correct
15 Correct 2 ms 2656 KB Output is correct
16 Correct 2 ms 2656 KB Output is correct
17 Correct 2 ms 2908 KB Output is correct
18 Correct 2 ms 2656 KB Output is correct
19 Correct 2 ms 2656 KB Output is correct
20 Correct 2 ms 2656 KB Output is correct
21 Correct 2 ms 2656 KB Output is correct
22 Correct 14 ms 7264 KB Output is correct
23 Correct 14 ms 7264 KB Output is correct
24 Correct 15 ms 7264 KB Output is correct
25 Correct 3 ms 1632 KB Output is correct
26 Correct 3 ms 1632 KB Output is correct
27 Correct 4 ms 1380 KB Output is correct
28 Correct 3 ms 1384 KB Output is correct
29 Correct 3 ms 1128 KB Output is correct
30 Correct 3 ms 1208 KB Output is correct
31 Correct 10 ms 5224 KB Output is correct
32 Correct 10 ms 5248 KB Output is correct
33 Correct 10 ms 5224 KB Output is correct
34 Correct 10 ms 5216 KB Output is correct
35 Correct 10 ms 5220 KB Output is correct
36 Correct 14 ms 5476 KB Output is correct
37 Correct 20 ms 8088 KB Output is correct
38 Correct 22 ms 8028 KB Output is correct
39 Correct 19 ms 8068 KB Output is correct
40 Correct 13 ms 5736 KB Output is correct
41 Correct 8 ms 3540 KB Output is correct
42 Correct 17 ms 5724 KB Output is correct
43 Correct 12 ms 3260 KB Output is correct
44 Correct 9 ms 2908 KB Output is correct
45 Correct 14 ms 4372 KB Output is correct
46 Correct 38 ms 16772 KB Output is correct
47 Correct 26 ms 11344 KB Output is correct
48 Correct 28 ms 13400 KB Output is correct
49 Correct 30 ms 12380 KB Output is correct
50 Correct 34 ms 12368 KB Output is correct
51 Correct 27 ms 9684 KB Output is correct
52 Correct 14 ms 5848 KB Output is correct
53 Correct 14 ms 5852 KB Output is correct
54 Correct 17 ms 5644 KB Output is correct
55 Correct 16 ms 4876 KB Output is correct
56 Correct 15 ms 4952 KB Output is correct
57 Correct 14 ms 4444 KB Output is correct
58 Correct 46 ms 18196 KB Output is correct
59 Correct 43 ms 18128 KB Output is correct
60 Correct 42 ms 18128 KB Output is correct
61 Correct 42 ms 18124 KB Output is correct
62 Correct 42 ms 18128 KB Output is correct
63 Correct 42 ms 18136 KB Output is correct
64 Correct 57 ms 15696 KB Output is correct
65 Correct 42 ms 15352 KB Output is correct
66 Correct 42 ms 15220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 440 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 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 448 KB Output is correct
13 Correct 3 ms 2652 KB Output is correct
14 Correct 2 ms 2656 KB Output is correct
15 Correct 2 ms 2656 KB Output is correct
16 Correct 2 ms 2656 KB Output is correct
17 Correct 2 ms 2908 KB Output is correct
18 Correct 2 ms 2656 KB Output is correct
19 Correct 2 ms 2656 KB Output is correct
20 Correct 2 ms 2656 KB Output is correct
21 Correct 2 ms 2656 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 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Incorrect 1 ms 604 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 440 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 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 448 KB Output is correct
15 Correct 3 ms 2652 KB Output is correct
16 Correct 2 ms 2656 KB Output is correct
17 Correct 2 ms 2656 KB Output is correct
18 Correct 2 ms 2656 KB Output is correct
19 Correct 2 ms 2908 KB Output is correct
20 Correct 2 ms 2656 KB Output is correct
21 Correct 2 ms 2656 KB Output is correct
22 Correct 2 ms 2656 KB Output is correct
23 Correct 2 ms 2656 KB Output is correct
24 Correct 14 ms 7264 KB Output is correct
25 Correct 14 ms 7264 KB Output is correct
26 Correct 15 ms 7264 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Incorrect 1 ms 604 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 440 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 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 448 KB Output is correct
15 Correct 3 ms 2652 KB Output is correct
16 Correct 2 ms 2656 KB Output is correct
17 Correct 2 ms 2656 KB Output is correct
18 Correct 2 ms 2656 KB Output is correct
19 Correct 2 ms 2908 KB Output is correct
20 Correct 2 ms 2656 KB Output is correct
21 Correct 2 ms 2656 KB Output is correct
22 Correct 2 ms 2656 KB Output is correct
23 Correct 2 ms 2656 KB Output is correct
24 Correct 14 ms 7264 KB Output is correct
25 Correct 14 ms 7264 KB Output is correct
26 Correct 15 ms 7264 KB Output is correct
27 Correct 3 ms 1632 KB Output is correct
28 Correct 3 ms 1632 KB Output is correct
29 Correct 4 ms 1380 KB Output is correct
30 Correct 3 ms 1384 KB Output is correct
31 Correct 3 ms 1128 KB Output is correct
32 Correct 3 ms 1208 KB Output is correct
33 Correct 10 ms 5224 KB Output is correct
34 Correct 10 ms 5248 KB Output is correct
35 Correct 10 ms 5224 KB Output is correct
36 Correct 10 ms 5216 KB Output is correct
37 Correct 10 ms 5220 KB Output is correct
38 Correct 14 ms 5476 KB Output is correct
39 Correct 20 ms 8088 KB Output is correct
40 Correct 22 ms 8028 KB Output is correct
41 Correct 19 ms 8068 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 344 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Incorrect 1 ms 604 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 440 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 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 448 KB Output is correct
15 Correct 3 ms 2652 KB Output is correct
16 Correct 2 ms 2656 KB Output is correct
17 Correct 2 ms 2656 KB Output is correct
18 Correct 2 ms 2656 KB Output is correct
19 Correct 2 ms 2908 KB Output is correct
20 Correct 2 ms 2656 KB Output is correct
21 Correct 2 ms 2656 KB Output is correct
22 Correct 2 ms 2656 KB Output is correct
23 Correct 2 ms 2656 KB Output is correct
24 Correct 14 ms 7264 KB Output is correct
25 Correct 14 ms 7264 KB Output is correct
26 Correct 15 ms 7264 KB Output is correct
27 Correct 3 ms 1632 KB Output is correct
28 Correct 3 ms 1632 KB Output is correct
29 Correct 4 ms 1380 KB Output is correct
30 Correct 3 ms 1384 KB Output is correct
31 Correct 3 ms 1128 KB Output is correct
32 Correct 3 ms 1208 KB Output is correct
33 Correct 10 ms 5224 KB Output is correct
34 Correct 10 ms 5248 KB Output is correct
35 Correct 10 ms 5224 KB Output is correct
36 Correct 10 ms 5216 KB Output is correct
37 Correct 10 ms 5220 KB Output is correct
38 Correct 14 ms 5476 KB Output is correct
39 Correct 20 ms 8088 KB Output is correct
40 Correct 22 ms 8028 KB Output is correct
41 Correct 19 ms 8068 KB Output is correct
42 Correct 13 ms 5736 KB Output is correct
43 Correct 8 ms 3540 KB Output is correct
44 Correct 17 ms 5724 KB Output is correct
45 Correct 12 ms 3260 KB Output is correct
46 Correct 9 ms 2908 KB Output is correct
47 Correct 14 ms 4372 KB Output is correct
48 Correct 38 ms 16772 KB Output is correct
49 Correct 26 ms 11344 KB Output is correct
50 Correct 28 ms 13400 KB Output is correct
51 Correct 30 ms 12380 KB Output is correct
52 Correct 34 ms 12368 KB Output is correct
53 Correct 27 ms 9684 KB Output is correct
54 Correct 14 ms 5848 KB Output is correct
55 Correct 14 ms 5852 KB Output is correct
56 Correct 17 ms 5644 KB Output is correct
57 Correct 16 ms 4876 KB Output is correct
58 Correct 15 ms 4952 KB Output is correct
59 Correct 14 ms 4444 KB Output is correct
60 Correct 46 ms 18196 KB Output is correct
61 Correct 43 ms 18128 KB Output is correct
62 Correct 42 ms 18128 KB Output is correct
63 Correct 42 ms 18124 KB Output is correct
64 Correct 42 ms 18128 KB Output is correct
65 Correct 42 ms 18136 KB Output is correct
66 Correct 57 ms 15696 KB Output is correct
67 Correct 42 ms 15352 KB Output is correct
68 Correct 42 ms 15220 KB Output is correct
69 Correct 0 ms 344 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
71 Correct 0 ms 344 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Incorrect 1 ms 604 KB Output isn't correct
74 Halted 0 ms 0 KB -