Submission #736376

# Submission time Handle Problem Language Result Execution time Memory
736376 2023-05-05T14:12:57 Z minhcool Painting Walls (APIO20_paint) C++17
0 / 100
7 ms 9684 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 = 4e5 + 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 - m) - 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 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 4 ms 9684 KB Output is correct
9 Correct 6 ms 9684 KB Output is correct
10 Correct 6 ms 9684 KB Output is correct
11 Correct 6 ms 9684 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Incorrect 7 ms 9684 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 4 ms 9684 KB Output is correct
9 Correct 6 ms 9684 KB Output is correct
10 Correct 6 ms 9684 KB Output is correct
11 Correct 6 ms 9684 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Incorrect 7 ms 9684 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 4 ms 9684 KB Output is correct
9 Correct 6 ms 9684 KB Output is correct
10 Correct 6 ms 9684 KB Output is correct
11 Correct 6 ms 9684 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Incorrect 7 ms 9684 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 4 ms 9684 KB Output is correct
9 Correct 6 ms 9684 KB Output is correct
10 Correct 6 ms 9684 KB Output is correct
11 Correct 6 ms 9684 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Incorrect 7 ms 9684 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 4 ms 9684 KB Output is correct
9 Correct 6 ms 9684 KB Output is correct
10 Correct 6 ms 9684 KB Output is correct
11 Correct 6 ms 9684 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Incorrect 7 ms 9684 KB Output isn't correct
14 Halted 0 ms 0 KB -