Submission #333581

# Submission time Handle Problem Language Result Execution time Memory
333581 2020-12-07T05:20:20 Z alishahali1382 Painting Walls (APIO20_paint) C++14
28 / 100
1500 ms 39436 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 debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const int inf=1000000010;
const int mod=1000000007;
const int MAXN=100010;

int n, m, k, x, y, ans;
int C[MAXN];
int dp[MAXN], F[MAXN];
vector<int> col[MAXN];
bool ok[2000][20001];

inline int is_bad(int c, int ins){
	return !ok[ins][c];
	int pos=lower_bound(all(col[ins]), c)-col[ins].begin();
	return (pos==col[ins].size() || col[ins][pos]!=c);
}

int minimumInstructions(int nn, int mm, int kk, vector<int> CC, vector<int> AA, vector<vector<int>> BB){
	n=nn;
	m=mm;
	for (int i=0; i<n; i++) C[i]=CC[i], F[i]=i;
	sort(all(CC));
	CC.resize(unique(all(CC))-CC.begin());
	k=min((int)CC.size()+1, kk);
	for (int i=0; i<n; i++) C[i]=lower_bound(all(CC), C[i])-CC.begin();
	
	for (int i=0; i<m; i++){
		col[i].resize(AA[i]);
		for (int j=0; j<AA[i]; j++){
			int tmp=lower_bound(all(CC), BB[i][j])-CC.begin();
			if (tmp==CC.size() || CC[tmp]!=BB[i][j]) col[i][j]=k-1;
			else col[i][j]=tmp;
			ok[i][col[i][j]]=1;
		}
		sort(all(col[i]));
	}
	
	
	for (int sh=0; sh<m; sh++){
		int bad=0;
		for (int i=0; i<n; i++){
			bad+=is_bad(C[i], (i+sh)%m);
			if (i>=m) bad-=is_bad(C[i-m], (i+sh)%m);
			if (i>=m-1 && bad==0) F[i]=min(F[i], i-m), debug(i);
			
		}
	}
	/*
	for (int x=0; x<m; x++) for (int y=0; y<=n-m; y++){
		bool bad=0;
		for (int l=y; l<y+m && !bad; l++) if (is_bad(C[l], (x+l)%m)) bad=1;
		if (bad) continue ;
		F[y+m-1]=min(F[y+m-1], y-1);
		debug2(y, y+m-1)
	}
	*/
	
	for (int i=n-2; ~i; i--) F[i]=min(F[i], F[i+1]);
	memset(dp, 63, sizeof(dp));
	for (int i=0; i<n; i++) if (F[i]!=i){
		if (F[i]==-1) dp[i]=1;
		else dp[i]=dp[F[i]]+1;
	}
	if (dp[n-1]>n) return -1;
	return dp[n-1];
}
/*
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 is_bad(int, int)':
paint.cpp:28:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |  return (pos==col[ins].size() || col[ins][pos]!=c);
      |          ~~~^~~~~~~~~~~~~~~~~
paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:44:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |    if (tmp==CC.size() || CC[tmp]!=BB[i][j]) col[i][j]=k-1;
      |        ~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3052 KB Output is correct
2 Correct 2 ms 3052 KB Output is correct
3 Correct 2 ms 3052 KB Output is correct
4 Correct 2 ms 3052 KB Output is correct
5 Correct 2 ms 3052 KB Output is correct
6 Correct 2 ms 3052 KB Output is correct
7 Correct 8 ms 3052 KB Output is correct
8 Correct 7 ms 3052 KB Output is correct
9 Correct 5 ms 3052 KB Output is correct
10 Correct 3 ms 3052 KB Output is correct
11 Correct 3 ms 3052 KB Output is correct
12 Correct 3 ms 3052 KB Output is correct
13 Correct 7 ms 3948 KB Output is correct
14 Correct 6 ms 3948 KB Output is correct
15 Correct 6 ms 3948 KB Output is correct
16 Correct 6 ms 3948 KB Output is correct
17 Correct 6 ms 3948 KB Output is correct
18 Correct 6 ms 3948 KB Output is correct
19 Correct 5 ms 3948 KB Output is correct
20 Correct 4 ms 3948 KB Output is correct
21 Correct 4 ms 3948 KB Output is correct
22 Correct 20 ms 5740 KB Output is correct
23 Correct 20 ms 5740 KB Output is correct
24 Correct 21 ms 5740 KB Output is correct
25 Correct 176 ms 3564 KB Output is correct
26 Correct 176 ms 3692 KB Output is correct
27 Correct 92 ms 3564 KB Output is correct
28 Correct 39 ms 3436 KB Output is correct
29 Correct 8 ms 3436 KB Output is correct
30 Correct 6 ms 3436 KB Output is correct
31 Execution timed out 1564 ms 39436 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3052 KB Output is correct
2 Correct 2 ms 3052 KB Output is correct
3 Correct 2 ms 3052 KB Output is correct
4 Correct 2 ms 3052 KB Output is correct
5 Correct 2 ms 3052 KB Output is correct
6 Correct 2 ms 3052 KB Output is correct
7 Correct 2 ms 3052 KB Output is correct
8 Correct 2 ms 3052 KB Output is correct
9 Correct 8 ms 3052 KB Output is correct
10 Correct 7 ms 3052 KB Output is correct
11 Correct 5 ms 3052 KB Output is correct
12 Correct 3 ms 3052 KB Output is correct
13 Correct 3 ms 3052 KB Output is correct
14 Correct 3 ms 3052 KB Output is correct
15 Correct 7 ms 3948 KB Output is correct
16 Correct 6 ms 3948 KB Output is correct
17 Correct 6 ms 3948 KB Output is correct
18 Correct 6 ms 3948 KB Output is correct
19 Correct 6 ms 3948 KB Output is correct
20 Correct 6 ms 3948 KB Output is correct
21 Correct 5 ms 3948 KB Output is correct
22 Correct 4 ms 3948 KB Output is correct
23 Correct 4 ms 3948 KB Output is correct
24 Correct 2 ms 3052 KB Output is correct
25 Correct 2 ms 3052 KB Output is correct
26 Correct 2 ms 3052 KB Output is correct
27 Correct 7 ms 3052 KB Output is correct
28 Correct 74 ms 3180 KB Output is correct
29 Correct 3 ms 3180 KB Output is correct
30 Correct 2 ms 3180 KB Output is correct
31 Correct 33 ms 3180 KB Output is correct
32 Correct 3 ms 3308 KB Output is correct
33 Correct 6 ms 3820 KB Output is correct
34 Correct 6 ms 3820 KB Output is correct
35 Correct 5 ms 3692 KB Output is correct
36 Correct 5 ms 3692 KB Output is correct
37 Correct 5 ms 3948 KB Output is correct
38 Correct 3 ms 3052 KB Output is correct
39 Correct 5 ms 3052 KB Output is correct
40 Correct 4 ms 3820 KB Output is correct
41 Correct 5 ms 3820 KB Output is correct
42 Correct 3 ms 3436 KB Output is correct
43 Correct 4 ms 3308 KB Output is correct
44 Correct 12 ms 3052 KB Output is correct
45 Correct 131 ms 3308 KB Output is correct
46 Correct 3 ms 3308 KB Output is correct
47 Correct 3 ms 3308 KB Output is correct
48 Correct 3 ms 3308 KB Output is correct
49 Correct 3 ms 3308 KB Output is correct
50 Correct 6 ms 3948 KB Output is correct
51 Correct 6 ms 3948 KB Output is correct
52 Correct 6 ms 3948 KB Output is correct
53 Correct 6 ms 3948 KB Output is correct
54 Correct 7 ms 3948 KB Output is correct
55 Correct 6 ms 3948 KB Output is correct
56 Correct 4 ms 3968 KB Output is correct
57 Correct 6 ms 3948 KB Output is correct
58 Correct 4 ms 3948 KB Output is correct
59 Correct 6 ms 3948 KB Output is correct
60 Correct 4 ms 3948 KB Output is correct
61 Correct 6 ms 3948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3052 KB Output is correct
2 Correct 2 ms 3052 KB Output is correct
3 Correct 2 ms 3052 KB Output is correct
4 Correct 2 ms 3052 KB Output is correct
5 Correct 2 ms 3052 KB Output is correct
6 Correct 2 ms 3052 KB Output is correct
7 Correct 2 ms 3052 KB Output is correct
8 Correct 2 ms 3052 KB Output is correct
9 Correct 8 ms 3052 KB Output is correct
10 Correct 7 ms 3052 KB Output is correct
11 Correct 5 ms 3052 KB Output is correct
12 Correct 3 ms 3052 KB Output is correct
13 Correct 3 ms 3052 KB Output is correct
14 Correct 3 ms 3052 KB Output is correct
15 Correct 7 ms 3948 KB Output is correct
16 Correct 6 ms 3948 KB Output is correct
17 Correct 6 ms 3948 KB Output is correct
18 Correct 6 ms 3948 KB Output is correct
19 Correct 6 ms 3948 KB Output is correct
20 Correct 6 ms 3948 KB Output is correct
21 Correct 5 ms 3948 KB Output is correct
22 Correct 4 ms 3948 KB Output is correct
23 Correct 4 ms 3948 KB Output is correct
24 Correct 20 ms 5740 KB Output is correct
25 Correct 20 ms 5740 KB Output is correct
26 Correct 21 ms 5740 KB Output is correct
27 Correct 2 ms 3052 KB Output is correct
28 Correct 2 ms 3052 KB Output is correct
29 Correct 2 ms 3052 KB Output is correct
30 Correct 7 ms 3052 KB Output is correct
31 Correct 74 ms 3180 KB Output is correct
32 Correct 3 ms 3180 KB Output is correct
33 Correct 2 ms 3180 KB Output is correct
34 Correct 33 ms 3180 KB Output is correct
35 Correct 3 ms 3308 KB Output is correct
36 Correct 6 ms 3820 KB Output is correct
37 Correct 6 ms 3820 KB Output is correct
38 Correct 5 ms 3692 KB Output is correct
39 Correct 5 ms 3692 KB Output is correct
40 Correct 5 ms 3948 KB Output is correct
41 Correct 3 ms 3052 KB Output is correct
42 Correct 5 ms 3052 KB Output is correct
43 Correct 4 ms 3820 KB Output is correct
44 Correct 5 ms 3820 KB Output is correct
45 Correct 3 ms 3436 KB Output is correct
46 Correct 4 ms 3308 KB Output is correct
47 Correct 12 ms 3052 KB Output is correct
48 Correct 131 ms 3308 KB Output is correct
49 Correct 3 ms 3308 KB Output is correct
50 Correct 3 ms 3308 KB Output is correct
51 Correct 3 ms 3308 KB Output is correct
52 Correct 3 ms 3308 KB Output is correct
53 Correct 6 ms 3948 KB Output is correct
54 Correct 6 ms 3948 KB Output is correct
55 Correct 6 ms 3948 KB Output is correct
56 Correct 6 ms 3948 KB Output is correct
57 Correct 7 ms 3948 KB Output is correct
58 Correct 6 ms 3948 KB Output is correct
59 Correct 4 ms 3968 KB Output is correct
60 Correct 6 ms 3948 KB Output is correct
61 Correct 4 ms 3948 KB Output is correct
62 Correct 6 ms 3948 KB Output is correct
63 Correct 4 ms 3948 KB Output is correct
64 Correct 6 ms 3948 KB Output is correct
65 Correct 111 ms 3948 KB Output is correct
66 Correct 150 ms 3308 KB Output is correct
67 Correct 392 ms 4040 KB Output is correct
68 Correct 263 ms 3712 KB Output is correct
69 Correct 334 ms 3820 KB Output is correct
70 Correct 14 ms 4076 KB Output is correct
71 Correct 18 ms 3948 KB Output is correct
72 Correct 34 ms 3692 KB Output is correct
73 Correct 53 ms 3308 KB Output is correct
74 Correct 27 ms 3820 KB Output is correct
75 Correct 9 ms 4076 KB Output is correct
76 Correct 20 ms 5484 KB Output is correct
77 Correct 22 ms 5228 KB Output is correct
78 Correct 24 ms 5740 KB Output is correct
79 Correct 514 ms 4332 KB Output is correct
80 Correct 522 ms 4332 KB Output is correct
81 Correct 517 ms 4332 KB Output is correct
82 Correct 522 ms 4332 KB Output is correct
83 Correct 519 ms 4332 KB Output is correct
84 Correct 26 ms 4332 KB Output is correct
85 Correct 20 ms 4332 KB Output is correct
86 Correct 20 ms 4332 KB Output is correct
87 Correct 17 ms 4332 KB Output is correct
88 Correct 20 ms 4332 KB Output is correct
89 Correct 21 ms 4332 KB Output is correct
90 Correct 29 ms 6764 KB Output is correct
91 Correct 29 ms 6636 KB Output is correct
92 Correct 29 ms 6764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3052 KB Output is correct
2 Correct 2 ms 3052 KB Output is correct
3 Correct 2 ms 3052 KB Output is correct
4 Correct 2 ms 3052 KB Output is correct
5 Correct 2 ms 3052 KB Output is correct
6 Correct 2 ms 3052 KB Output is correct
7 Correct 2 ms 3052 KB Output is correct
8 Correct 2 ms 3052 KB Output is correct
9 Correct 8 ms 3052 KB Output is correct
10 Correct 7 ms 3052 KB Output is correct
11 Correct 5 ms 3052 KB Output is correct
12 Correct 3 ms 3052 KB Output is correct
13 Correct 3 ms 3052 KB Output is correct
14 Correct 3 ms 3052 KB Output is correct
15 Correct 7 ms 3948 KB Output is correct
16 Correct 6 ms 3948 KB Output is correct
17 Correct 6 ms 3948 KB Output is correct
18 Correct 6 ms 3948 KB Output is correct
19 Correct 6 ms 3948 KB Output is correct
20 Correct 6 ms 3948 KB Output is correct
21 Correct 5 ms 3948 KB Output is correct
22 Correct 4 ms 3948 KB Output is correct
23 Correct 4 ms 3948 KB Output is correct
24 Correct 20 ms 5740 KB Output is correct
25 Correct 20 ms 5740 KB Output is correct
26 Correct 21 ms 5740 KB Output is correct
27 Correct 176 ms 3564 KB Output is correct
28 Correct 176 ms 3692 KB Output is correct
29 Correct 92 ms 3564 KB Output is correct
30 Correct 39 ms 3436 KB Output is correct
31 Correct 8 ms 3436 KB Output is correct
32 Correct 6 ms 3436 KB Output is correct
33 Execution timed out 1564 ms 39436 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3052 KB Output is correct
2 Correct 2 ms 3052 KB Output is correct
3 Correct 2 ms 3052 KB Output is correct
4 Correct 2 ms 3052 KB Output is correct
5 Correct 2 ms 3052 KB Output is correct
6 Correct 2 ms 3052 KB Output is correct
7 Correct 2 ms 3052 KB Output is correct
8 Correct 2 ms 3052 KB Output is correct
9 Correct 8 ms 3052 KB Output is correct
10 Correct 7 ms 3052 KB Output is correct
11 Correct 5 ms 3052 KB Output is correct
12 Correct 3 ms 3052 KB Output is correct
13 Correct 3 ms 3052 KB Output is correct
14 Correct 3 ms 3052 KB Output is correct
15 Correct 7 ms 3948 KB Output is correct
16 Correct 6 ms 3948 KB Output is correct
17 Correct 6 ms 3948 KB Output is correct
18 Correct 6 ms 3948 KB Output is correct
19 Correct 6 ms 3948 KB Output is correct
20 Correct 6 ms 3948 KB Output is correct
21 Correct 5 ms 3948 KB Output is correct
22 Correct 4 ms 3948 KB Output is correct
23 Correct 4 ms 3948 KB Output is correct
24 Correct 20 ms 5740 KB Output is correct
25 Correct 20 ms 5740 KB Output is correct
26 Correct 21 ms 5740 KB Output is correct
27 Correct 176 ms 3564 KB Output is correct
28 Correct 176 ms 3692 KB Output is correct
29 Correct 92 ms 3564 KB Output is correct
30 Correct 39 ms 3436 KB Output is correct
31 Correct 8 ms 3436 KB Output is correct
32 Correct 6 ms 3436 KB Output is correct
33 Execution timed out 1564 ms 39436 KB Time limit exceeded
34 Halted 0 ms 0 KB -