Submission #736373

# Submission time Handle Problem Language Result Execution time Memory
736373 2023-05-05T14:01:14 Z minhcool Painting Walls (APIO20_paint) C++17
0 / 100
30 ms 12380 KB
#include "paint.h"
#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;

const int N = 3e5 + 5;

const int oo = 1e18 + 7, mod = 1e9 + 7;

int n, m, k;

int arr[N];

vector<int> like[N];

int total[N], cnt[N];

bool okay[N];

int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B){
	n = N, m = M, k = K;
	for(int i = 0; i < n; i++) arr[i + 1] = C[i] + 1;
	for(int i = 0; i < m; i++){
		for(auto it : B[i]) like[it + 1].pb(i + 1);
	}
	for(int i = 1; i <= k; i++) assert(like[i].size() <= 700);
	for(int i = 1; i <= m; i++){
		for(auto it : like[arr[i]]){
			int temp = (it - (i - 1) + 2 * m) % m;
			if(!temp) temp = m;
			total[temp]++;
			//okay[1] |= (total[temp] == m);
		}
	}
	for(int i = 1; i <= m; i++) cnt[total[i]]++;
	okay[1] = (cnt[m] != 0);
	for(int i = m + 1; i <= n; i++){
		for(auto it : like[arr[i - m]]){
			int temp = (it - (i - 1) + 2 * m) % m;
			if(!temp) temp = m;
			cnt[total[temp]]--;
			total[temp]--;
			cnt[total[temp]]++;
			//total[temp]++;
		}
		for(auto it : like[arr[i]]){
			int temp = (it - (i - 1) + 2 * m) % m;
			if(!temp) temp = m;
			cnt[total[temp]]--;
			total[temp]++;
			cnt[total[temp]]++;
		}
		okay[i - m + 1] = (cnt[m] != 0);
	}
	//for(int i = 1; i <= (n - m + 1); i++) cout << okay[i] << " ";
	//cout << "\n";
	if(!okay[1]) return -1;
	vector<int> okays;
	for(int i = 1; i <= n - m + 1; i++) if(okay[i]) okays.pb(i);
	int ans = 1, itr = m;
	while(itr < n){
		//cout << itr << "\n";
		vector<int>::iterator it = lower_bound(okays.begin(), okays.end(), itr + 2);
		assert(it != okays.begin());
		it--;
		int temp = ((*it) + m - 1);
		if(temp <= itr) return -1;
		itr = temp;
		ans++;
	}
	return ans;
}

Compilation message

paint.cpp:16:21: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   16 | const int oo = 1e18 + 7, mod = 1e9 + 7;
      |                ~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7380 KB Output is correct
2 Correct 5 ms 7252 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 4 ms 7252 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 4 ms 7252 KB Output is correct
7 Correct 4 ms 7364 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 4 ms 7360 KB Output is correct
10 Correct 5 ms 7252 KB Output is correct
11 Correct 4 ms 7368 KB Output is correct
12 Correct 4 ms 7380 KB Output is correct
13 Correct 4 ms 7364 KB Output is correct
14 Correct 4 ms 7360 KB Output is correct
15 Correct 4 ms 7380 KB Output is correct
16 Correct 4 ms 7360 KB Output is correct
17 Correct 4 ms 7380 KB Output is correct
18 Correct 5 ms 7380 KB Output is correct
19 Correct 5 ms 7380 KB Output is correct
20 Correct 4 ms 7368 KB Output is correct
21 Correct 5 ms 7368 KB Output is correct
22 Correct 22 ms 11772 KB Output is correct
23 Correct 21 ms 11756 KB Output is correct
24 Correct 23 ms 11852 KB Output is correct
25 Correct 8 ms 7772 KB Output is correct
26 Correct 8 ms 7804 KB Output is correct
27 Correct 7 ms 7636 KB Output is correct
28 Correct 8 ms 7604 KB Output is correct
29 Correct 7 ms 7636 KB Output is correct
30 Correct 7 ms 7552 KB Output is correct
31 Correct 11 ms 8904 KB Output is correct
32 Correct 12 ms 8948 KB Output is correct
33 Correct 11 ms 8908 KB Output is correct
34 Correct 12 ms 8916 KB Output is correct
35 Correct 12 ms 8956 KB Output is correct
36 Correct 13 ms 8916 KB Output is correct
37 Correct 27 ms 12380 KB Output is correct
38 Correct 29 ms 12376 KB Output is correct
39 Correct 30 ms 12372 KB Output is correct
40 Correct 20 ms 9308 KB Output is correct
41 Correct 14 ms 8532 KB Output is correct
42 Incorrect 20 ms 9420 KB Output isn't correct
43 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7380 KB Output is correct
2 Correct 5 ms 7252 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 4 ms 7252 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 4 ms 7252 KB Output is correct
7 Correct 4 ms 7364 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 4 ms 7360 KB Output is correct
10 Correct 5 ms 7252 KB Output is correct
11 Correct 4 ms 7368 KB Output is correct
12 Correct 4 ms 7380 KB Output is correct
13 Correct 4 ms 7364 KB Output is correct
14 Correct 4 ms 7360 KB Output is correct
15 Correct 4 ms 7380 KB Output is correct
16 Correct 4 ms 7360 KB Output is correct
17 Correct 4 ms 7380 KB Output is correct
18 Correct 5 ms 7380 KB Output is correct
19 Correct 5 ms 7380 KB Output is correct
20 Correct 4 ms 7368 KB Output is correct
21 Correct 5 ms 7368 KB Output is correct
22 Correct 4 ms 7360 KB Output is correct
23 Correct 4 ms 7252 KB Output is correct
24 Correct 4 ms 7252 KB Output is correct
25 Correct 4 ms 7252 KB Output is correct
26 Correct 4 ms 7252 KB Output is correct
27 Correct 4 ms 7380 KB Output is correct
28 Correct 4 ms 7380 KB Output is correct
29 Correct 4 ms 7380 KB Output is correct
30 Correct 4 ms 7380 KB Output is correct
31 Correct 4 ms 7352 KB Output is correct
32 Correct 4 ms 7380 KB Output is correct
33 Correct 5 ms 7380 KB Output is correct
34 Correct 4 ms 7364 KB Output is correct
35 Correct 4 ms 7380 KB Output is correct
36 Correct 4 ms 7380 KB Output is correct
37 Correct 5 ms 7364 KB Output is correct
38 Correct 4 ms 7380 KB Output is correct
39 Correct 4 ms 7380 KB Output is correct
40 Correct 5 ms 7380 KB Output is correct
41 Correct 6 ms 7356 KB Output is correct
42 Correct 4 ms 7380 KB Output is correct
43 Incorrect 4 ms 7380 KB Output isn't correct
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7360 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 5 ms 7380 KB Output is correct
4 Correct 5 ms 7252 KB Output is correct
5 Correct 4 ms 7252 KB Output is correct
6 Correct 4 ms 7252 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7252 KB Output is correct
9 Correct 4 ms 7364 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
11 Correct 4 ms 7360 KB Output is correct
12 Correct 5 ms 7252 KB Output is correct
13 Correct 4 ms 7368 KB Output is correct
14 Correct 4 ms 7380 KB Output is correct
15 Correct 4 ms 7364 KB Output is correct
16 Correct 4 ms 7360 KB Output is correct
17 Correct 4 ms 7380 KB Output is correct
18 Correct 4 ms 7360 KB Output is correct
19 Correct 4 ms 7380 KB Output is correct
20 Correct 5 ms 7380 KB Output is correct
21 Correct 5 ms 7380 KB Output is correct
22 Correct 4 ms 7368 KB Output is correct
23 Correct 5 ms 7368 KB Output is correct
24 Correct 22 ms 11772 KB Output is correct
25 Correct 21 ms 11756 KB Output is correct
26 Correct 23 ms 11852 KB Output is correct
27 Correct 4 ms 7252 KB Output is correct
28 Correct 4 ms 7252 KB Output is correct
29 Correct 4 ms 7252 KB Output is correct
30 Correct 4 ms 7380 KB Output is correct
31 Correct 4 ms 7380 KB Output is correct
32 Correct 4 ms 7380 KB Output is correct
33 Correct 4 ms 7380 KB Output is correct
34 Correct 4 ms 7352 KB Output is correct
35 Correct 4 ms 7380 KB Output is correct
36 Correct 5 ms 7380 KB Output is correct
37 Correct 4 ms 7364 KB Output is correct
38 Correct 4 ms 7380 KB Output is correct
39 Correct 4 ms 7380 KB Output is correct
40 Correct 5 ms 7364 KB Output is correct
41 Correct 4 ms 7380 KB Output is correct
42 Correct 4 ms 7380 KB Output is correct
43 Correct 5 ms 7380 KB Output is correct
44 Correct 6 ms 7356 KB Output is correct
45 Correct 4 ms 7380 KB Output is correct
46 Incorrect 4 ms 7380 KB Output isn't correct
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7360 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 5 ms 7380 KB Output is correct
4 Correct 5 ms 7252 KB Output is correct
5 Correct 4 ms 7252 KB Output is correct
6 Correct 4 ms 7252 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7252 KB Output is correct
9 Correct 4 ms 7364 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
11 Correct 4 ms 7360 KB Output is correct
12 Correct 5 ms 7252 KB Output is correct
13 Correct 4 ms 7368 KB Output is correct
14 Correct 4 ms 7380 KB Output is correct
15 Correct 4 ms 7364 KB Output is correct
16 Correct 4 ms 7360 KB Output is correct
17 Correct 4 ms 7380 KB Output is correct
18 Correct 4 ms 7360 KB Output is correct
19 Correct 4 ms 7380 KB Output is correct
20 Correct 5 ms 7380 KB Output is correct
21 Correct 5 ms 7380 KB Output is correct
22 Correct 4 ms 7368 KB Output is correct
23 Correct 5 ms 7368 KB Output is correct
24 Correct 22 ms 11772 KB Output is correct
25 Correct 21 ms 11756 KB Output is correct
26 Correct 23 ms 11852 KB Output is correct
27 Correct 8 ms 7772 KB Output is correct
28 Correct 8 ms 7804 KB Output is correct
29 Correct 7 ms 7636 KB Output is correct
30 Correct 8 ms 7604 KB Output is correct
31 Correct 7 ms 7636 KB Output is correct
32 Correct 7 ms 7552 KB Output is correct
33 Correct 11 ms 8904 KB Output is correct
34 Correct 12 ms 8948 KB Output is correct
35 Correct 11 ms 8908 KB Output is correct
36 Correct 12 ms 8916 KB Output is correct
37 Correct 12 ms 8956 KB Output is correct
38 Correct 13 ms 8916 KB Output is correct
39 Correct 27 ms 12380 KB Output is correct
40 Correct 29 ms 12376 KB Output is correct
41 Correct 30 ms 12372 KB Output is correct
42 Correct 4 ms 7252 KB Output is correct
43 Correct 4 ms 7252 KB Output is correct
44 Correct 4 ms 7252 KB Output is correct
45 Correct 4 ms 7380 KB Output is correct
46 Correct 4 ms 7380 KB Output is correct
47 Correct 4 ms 7380 KB Output is correct
48 Correct 4 ms 7380 KB Output is correct
49 Correct 4 ms 7352 KB Output is correct
50 Correct 4 ms 7380 KB Output is correct
51 Correct 5 ms 7380 KB Output is correct
52 Correct 4 ms 7364 KB Output is correct
53 Correct 4 ms 7380 KB Output is correct
54 Correct 4 ms 7380 KB Output is correct
55 Correct 5 ms 7364 KB Output is correct
56 Correct 4 ms 7380 KB Output is correct
57 Correct 4 ms 7380 KB Output is correct
58 Correct 5 ms 7380 KB Output is correct
59 Correct 6 ms 7356 KB Output is correct
60 Correct 4 ms 7380 KB Output is correct
61 Incorrect 4 ms 7380 KB Output isn't correct
62 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7360 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 5 ms 7380 KB Output is correct
4 Correct 5 ms 7252 KB Output is correct
5 Correct 4 ms 7252 KB Output is correct
6 Correct 4 ms 7252 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7252 KB Output is correct
9 Correct 4 ms 7364 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
11 Correct 4 ms 7360 KB Output is correct
12 Correct 5 ms 7252 KB Output is correct
13 Correct 4 ms 7368 KB Output is correct
14 Correct 4 ms 7380 KB Output is correct
15 Correct 4 ms 7364 KB Output is correct
16 Correct 4 ms 7360 KB Output is correct
17 Correct 4 ms 7380 KB Output is correct
18 Correct 4 ms 7360 KB Output is correct
19 Correct 4 ms 7380 KB Output is correct
20 Correct 5 ms 7380 KB Output is correct
21 Correct 5 ms 7380 KB Output is correct
22 Correct 4 ms 7368 KB Output is correct
23 Correct 5 ms 7368 KB Output is correct
24 Correct 22 ms 11772 KB Output is correct
25 Correct 21 ms 11756 KB Output is correct
26 Correct 23 ms 11852 KB Output is correct
27 Correct 8 ms 7772 KB Output is correct
28 Correct 8 ms 7804 KB Output is correct
29 Correct 7 ms 7636 KB Output is correct
30 Correct 8 ms 7604 KB Output is correct
31 Correct 7 ms 7636 KB Output is correct
32 Correct 7 ms 7552 KB Output is correct
33 Correct 11 ms 8904 KB Output is correct
34 Correct 12 ms 8948 KB Output is correct
35 Correct 11 ms 8908 KB Output is correct
36 Correct 12 ms 8916 KB Output is correct
37 Correct 12 ms 8956 KB Output is correct
38 Correct 13 ms 8916 KB Output is correct
39 Correct 27 ms 12380 KB Output is correct
40 Correct 29 ms 12376 KB Output is correct
41 Correct 30 ms 12372 KB Output is correct
42 Correct 20 ms 9308 KB Output is correct
43 Correct 14 ms 8532 KB Output is correct
44 Incorrect 20 ms 9420 KB Output isn't correct
45 Halted 0 ms 0 KB -