답안 #387147

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
387147 2021-04-08T04:05:54 Z talant117408 벽 칠하기 (APIO20_paint) C++17
28 / 100
1500 ms 11628 KB
#include "paint.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

#define sz(v) (int)v.size()
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()

const int MAXN = 1e5+7;
int n, m, k;
int color[MAXN];
//~ vector <int> isLiked[MAXN];
map <pii, bool> isLiked;

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++) color[i] = C[i];
	for (int i = 0; i < m; i++) {
		for (auto to : B[i]) {
			isLiked[mp(to, i)] = 1;
		}
	}
	int fk = 0;
	for (int i = 0; i < k; i++) {
		//fk = max(fk, sz(isLiked[i]));
	}
	
	/*if (fk < 2) {
		for (int i = 0; i+m < n; i++) {
			if (color[i] != color[i+m]) return -1;
		}
		if (sz(isLiked[color[0]]) == 0) {
			return -1;
		}
		else {
			int start = isLiked[color[0]].back();
			for (int i = 0; i < m; i++) {
				if (sz(isLiked[color[i]]) == 0 || isLiked[color[i]].back() != (start+i)%m) {
					return -1;
				}
			}	
		}
		return (n+m-1)/m;
	}
	else {*/
		vector <int> pos;
		for (int start = 0; start < m; start++) {
			int bad = 0;
			for (int i = 0; i < n; i++) {
				if (!isLiked.count(mp(color[i], (start+i)%m))) {
					bad++;
				}
				if (i >= m) {
					if (!isLiked.count(mp(color[i-m], (start+i-m)%m))) {
						bad--;
					}
				}
				if (i >= m-1 && bad == 0) {
					pos.pb(i-m+1);
				}
			}
		}
		sort(all(pos));
		if (sz(pos) == 0) return -1;
		vector <int> v;
		for (int i = 0; i < sz(pos); i++) {
			if (sz(v) == 0 || (sz(v) == 1 && v.back() != pos[i])) {
				v.pb(pos[i]);
			}
			else if (v[sz(v)-2]+m >= pos[i]) {
				v.pop_back();
				v.pb(pos[i]);
			}
			else if (v.back() != pos[i]) {
				v.pb(pos[i]);
			}
		}
		int flag = 1, cnt = 0;
		vector <int> pref(n), have(n);
		for (auto to : pos) {
			pref[to]++;
			if (to + m < n) pref[to+m]--;
		}
		for (int i = 0; i < n; i++) {
			cnt += pref[i];
			if (cnt) have[i] = 1;
		}
		for (int i = 0; i < n; i++) {
			if (!have[i]) flag = 0;
		}
		if (flag == 0) return -1;
		return sz(v);
//	}
	
	return 0;
}

/*
8 3 5
3 3 1 3 4 4 2 2
3 0 1 2
2 2 3
2 3 4
*/

Compilation message

paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:29:6: warning: unused variable 'fk' [-Wunused-variable]
   29 |  int fk = 0;
      |      ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 9 ms 364 KB Output is correct
14 Correct 9 ms 364 KB Output is correct
15 Correct 10 ms 364 KB Output is correct
16 Correct 10 ms 364 KB Output is correct
17 Correct 9 ms 364 KB Output is correct
18 Correct 10 ms 364 KB Output is correct
19 Correct 9 ms 364 KB Output is correct
20 Correct 9 ms 364 KB Output is correct
21 Correct 10 ms 364 KB Output is correct
22 Correct 77 ms 7404 KB Output is correct
23 Correct 113 ms 7424 KB Output is correct
24 Correct 85 ms 7404 KB Output is correct
25 Correct 4 ms 896 KB Output is correct
26 Correct 6 ms 876 KB Output is correct
27 Correct 6 ms 876 KB Output is correct
28 Correct 5 ms 748 KB Output is correct
29 Correct 8 ms 748 KB Output is correct
30 Correct 9 ms 748 KB Output is correct
31 Execution timed out 1589 ms 2028 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 9 ms 364 KB Output is correct
14 Correct 9 ms 364 KB Output is correct
15 Correct 10 ms 364 KB Output is correct
16 Correct 10 ms 364 KB Output is correct
17 Correct 9 ms 364 KB Output is correct
18 Correct 10 ms 364 KB Output is correct
19 Correct 9 ms 364 KB Output is correct
20 Correct 9 ms 364 KB Output is correct
21 Correct 10 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 2 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 2 ms 364 KB Output is correct
31 Correct 2 ms 364 KB Output is correct
32 Correct 2 ms 364 KB Output is correct
33 Correct 6 ms 364 KB Output is correct
34 Correct 6 ms 364 KB Output is correct
35 Correct 3 ms 364 KB Output is correct
36 Correct 5 ms 364 KB Output is correct
37 Correct 5 ms 508 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 2 ms 364 KB Output is correct
40 Correct 5 ms 364 KB Output is correct
41 Correct 5 ms 364 KB Output is correct
42 Correct 4 ms 364 KB Output is correct
43 Correct 3 ms 364 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 2 ms 492 KB Output is correct
46 Correct 2 ms 364 KB Output is correct
47 Correct 3 ms 364 KB Output is correct
48 Correct 3 ms 364 KB Output is correct
49 Correct 3 ms 364 KB Output is correct
50 Correct 9 ms 364 KB Output is correct
51 Correct 9 ms 364 KB Output is correct
52 Correct 9 ms 364 KB Output is correct
53 Correct 9 ms 364 KB Output is correct
54 Correct 9 ms 364 KB Output is correct
55 Correct 9 ms 364 KB Output is correct
56 Correct 10 ms 364 KB Output is correct
57 Correct 9 ms 364 KB Output is correct
58 Correct 9 ms 364 KB Output is correct
59 Correct 11 ms 492 KB Output is correct
60 Correct 10 ms 364 KB Output is correct
61 Correct 9 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 9 ms 364 KB Output is correct
16 Correct 9 ms 364 KB Output is correct
17 Correct 10 ms 364 KB Output is correct
18 Correct 10 ms 364 KB Output is correct
19 Correct 9 ms 364 KB Output is correct
20 Correct 10 ms 364 KB Output is correct
21 Correct 9 ms 364 KB Output is correct
22 Correct 9 ms 364 KB Output is correct
23 Correct 10 ms 364 KB Output is correct
24 Correct 77 ms 7404 KB Output is correct
25 Correct 113 ms 7424 KB Output is correct
26 Correct 85 ms 7404 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 2 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 2 ms 364 KB Output is correct
34 Correct 2 ms 364 KB Output is correct
35 Correct 2 ms 364 KB Output is correct
36 Correct 6 ms 364 KB Output is correct
37 Correct 6 ms 364 KB Output is correct
38 Correct 3 ms 364 KB Output is correct
39 Correct 5 ms 364 KB Output is correct
40 Correct 5 ms 508 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 2 ms 364 KB Output is correct
43 Correct 5 ms 364 KB Output is correct
44 Correct 5 ms 364 KB Output is correct
45 Correct 4 ms 364 KB Output is correct
46 Correct 3 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 2 ms 492 KB Output is correct
49 Correct 2 ms 364 KB Output is correct
50 Correct 3 ms 364 KB Output is correct
51 Correct 3 ms 364 KB Output is correct
52 Correct 3 ms 364 KB Output is correct
53 Correct 9 ms 364 KB Output is correct
54 Correct 9 ms 364 KB Output is correct
55 Correct 9 ms 364 KB Output is correct
56 Correct 9 ms 364 KB Output is correct
57 Correct 9 ms 364 KB Output is correct
58 Correct 9 ms 364 KB Output is correct
59 Correct 10 ms 364 KB Output is correct
60 Correct 9 ms 364 KB Output is correct
61 Correct 9 ms 364 KB Output is correct
62 Correct 11 ms 492 KB Output is correct
63 Correct 10 ms 364 KB Output is correct
64 Correct 9 ms 364 KB Output is correct
65 Correct 4 ms 492 KB Output is correct
66 Correct 4 ms 492 KB Output is correct
67 Correct 9 ms 748 KB Output is correct
68 Correct 6 ms 620 KB Output is correct
69 Correct 9 ms 748 KB Output is correct
70 Correct 22 ms 1132 KB Output is correct
71 Correct 19 ms 1132 KB Output is correct
72 Correct 13 ms 1088 KB Output is correct
73 Correct 5 ms 748 KB Output is correct
74 Correct 13 ms 1132 KB Output is correct
75 Correct 14 ms 876 KB Output is correct
76 Correct 60 ms 8300 KB Output is correct
77 Correct 42 ms 8940 KB Output is correct
78 Correct 66 ms 10476 KB Output is correct
79 Correct 12 ms 748 KB Output is correct
80 Correct 12 ms 748 KB Output is correct
81 Correct 13 ms 752 KB Output is correct
82 Correct 16 ms 900 KB Output is correct
83 Correct 14 ms 748 KB Output is correct
84 Correct 27 ms 1388 KB Output is correct
85 Correct 27 ms 1388 KB Output is correct
86 Correct 31 ms 1388 KB Output is correct
87 Correct 30 ms 1388 KB Output is correct
88 Correct 30 ms 1388 KB Output is correct
89 Correct 29 ms 1388 KB Output is correct
90 Correct 127 ms 11372 KB Output is correct
91 Correct 130 ms 11372 KB Output is correct
92 Correct 143 ms 11628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 9 ms 364 KB Output is correct
16 Correct 9 ms 364 KB Output is correct
17 Correct 10 ms 364 KB Output is correct
18 Correct 10 ms 364 KB Output is correct
19 Correct 9 ms 364 KB Output is correct
20 Correct 10 ms 364 KB Output is correct
21 Correct 9 ms 364 KB Output is correct
22 Correct 9 ms 364 KB Output is correct
23 Correct 10 ms 364 KB Output is correct
24 Correct 77 ms 7404 KB Output is correct
25 Correct 113 ms 7424 KB Output is correct
26 Correct 85 ms 7404 KB Output is correct
27 Correct 4 ms 896 KB Output is correct
28 Correct 6 ms 876 KB Output is correct
29 Correct 6 ms 876 KB Output is correct
30 Correct 5 ms 748 KB Output is correct
31 Correct 8 ms 748 KB Output is correct
32 Correct 9 ms 748 KB Output is correct
33 Execution timed out 1589 ms 2028 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 9 ms 364 KB Output is correct
16 Correct 9 ms 364 KB Output is correct
17 Correct 10 ms 364 KB Output is correct
18 Correct 10 ms 364 KB Output is correct
19 Correct 9 ms 364 KB Output is correct
20 Correct 10 ms 364 KB Output is correct
21 Correct 9 ms 364 KB Output is correct
22 Correct 9 ms 364 KB Output is correct
23 Correct 10 ms 364 KB Output is correct
24 Correct 77 ms 7404 KB Output is correct
25 Correct 113 ms 7424 KB Output is correct
26 Correct 85 ms 7404 KB Output is correct
27 Correct 4 ms 896 KB Output is correct
28 Correct 6 ms 876 KB Output is correct
29 Correct 6 ms 876 KB Output is correct
30 Correct 5 ms 748 KB Output is correct
31 Correct 8 ms 748 KB Output is correct
32 Correct 9 ms 748 KB Output is correct
33 Execution timed out 1589 ms 2028 KB Time limit exceeded
34 Halted 0 ms 0 KB -