# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
736384 | minhcool | Painting Walls (APIO20_paint) | C++17 | 7 ms | 9716 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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];
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);
}
}
int cnt = 0;
for(int i = 1; i <= m; i++) cnt += (total[i] == m);
okay[1] = (cnt != 0);
int temp = (n / m) + 1;
temp *= m;
for(int i = m + 1; i <= n; i++){
for(auto it : like[arr[i - m]]){
int temp = (it - i + 1 + temp) % m;
// cout << i << " " << temp << "\n";
if(!temp) temp = m;
if(total[temp] == m) cnt--;
//cnt[total[temp]]--;
total[temp]--;
//cnt[total[temp]]++;
//total[temp]++;
}
for(auto it : like[arr[i]]){
int temp = (it - i + 1 + temp) % m;
if(!temp) temp = m;
//cnt[total[temp]]--;
total[temp]++;
if(total[temp] == m) cnt++;
//cnt[total[temp]]++;
}
okay[i - m + 1] = (cnt != 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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |