# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
736384 | 2023-05-05T14:22:52 Z | minhcool | Painting Walls (APIO20_paint) | C++17 | 7 ms | 9716 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]; 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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 9636 KB | Output is correct |
2 | Correct | 5 ms | 9684 KB | Output is correct |
3 | Correct | 5 ms | 9708 KB | Output is correct |
4 | Correct | 5 ms | 9684 KB | Output is correct |
5 | Correct | 5 ms | 9716 KB | Output is correct |
6 | Correct | 6 ms | 9684 KB | Output is correct |
7 | Correct | 6 ms | 9704 KB | Output is correct |
8 | Correct | 7 ms | 9684 KB | Output is correct |
9 | Correct | 7 ms | 9684 KB | Output is correct |
10 | Correct | 6 ms | 9684 KB | Output is correct |
11 | Correct | 5 ms | 9684 KB | Output is correct |
12 | Correct | 5 ms | 9684 KB | Output is correct |
13 | Correct | 6 ms | 9712 KB | Output is correct |
14 | Correct | 5 ms | 9684 KB | Output is correct |
15 | Incorrect | 5 ms | 9684 KB | Output isn't correct |
16 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 9636 KB | Output is correct |
2 | Correct | 5 ms | 9684 KB | Output is correct |
3 | Correct | 5 ms | 9708 KB | Output is correct |
4 | Correct | 5 ms | 9684 KB | Output is correct |
5 | Correct | 5 ms | 9716 KB | Output is correct |
6 | Correct | 6 ms | 9684 KB | Output is correct |
7 | Correct | 6 ms | 9704 KB | Output is correct |
8 | Correct | 7 ms | 9684 KB | Output is correct |
9 | Correct | 7 ms | 9684 KB | Output is correct |
10 | Correct | 6 ms | 9684 KB | Output is correct |
11 | Correct | 5 ms | 9684 KB | Output is correct |
12 | Correct | 5 ms | 9684 KB | Output is correct |
13 | Correct | 6 ms | 9712 KB | Output is correct |
14 | Correct | 5 ms | 9684 KB | Output is correct |
15 | Incorrect | 5 ms | 9684 KB | Output isn't correct |
16 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 9636 KB | Output is correct |
2 | Correct | 5 ms | 9684 KB | Output is correct |
3 | Correct | 5 ms | 9708 KB | Output is correct |
4 | Correct | 5 ms | 9684 KB | Output is correct |
5 | Correct | 5 ms | 9716 KB | Output is correct |
6 | Correct | 6 ms | 9684 KB | Output is correct |
7 | Correct | 6 ms | 9704 KB | Output is correct |
8 | Correct | 7 ms | 9684 KB | Output is correct |
9 | Correct | 7 ms | 9684 KB | Output is correct |
10 | Correct | 6 ms | 9684 KB | Output is correct |
11 | Correct | 5 ms | 9684 KB | Output is correct |
12 | Correct | 5 ms | 9684 KB | Output is correct |
13 | Correct | 6 ms | 9712 KB | Output is correct |
14 | Correct | 5 ms | 9684 KB | Output is correct |
15 | Incorrect | 5 ms | 9684 KB | Output isn't correct |
16 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 9636 KB | Output is correct |
2 | Correct | 5 ms | 9684 KB | Output is correct |
3 | Correct | 5 ms | 9708 KB | Output is correct |
4 | Correct | 5 ms | 9684 KB | Output is correct |
5 | Correct | 5 ms | 9716 KB | Output is correct |
6 | Correct | 6 ms | 9684 KB | Output is correct |
7 | Correct | 6 ms | 9704 KB | Output is correct |
8 | Correct | 7 ms | 9684 KB | Output is correct |
9 | Correct | 7 ms | 9684 KB | Output is correct |
10 | Correct | 6 ms | 9684 KB | Output is correct |
11 | Correct | 5 ms | 9684 KB | Output is correct |
12 | Correct | 5 ms | 9684 KB | Output is correct |
13 | Correct | 6 ms | 9712 KB | Output is correct |
14 | Correct | 5 ms | 9684 KB | Output is correct |
15 | Incorrect | 5 ms | 9684 KB | Output isn't correct |
16 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 9636 KB | Output is correct |
2 | Correct | 5 ms | 9684 KB | Output is correct |
3 | Correct | 5 ms | 9708 KB | Output is correct |
4 | Correct | 5 ms | 9684 KB | Output is correct |
5 | Correct | 5 ms | 9716 KB | Output is correct |
6 | Correct | 6 ms | 9684 KB | Output is correct |
7 | Correct | 6 ms | 9704 KB | Output is correct |
8 | Correct | 7 ms | 9684 KB | Output is correct |
9 | Correct | 7 ms | 9684 KB | Output is correct |
10 | Correct | 6 ms | 9684 KB | Output is correct |
11 | Correct | 5 ms | 9684 KB | Output is correct |
12 | Correct | 5 ms | 9684 KB | Output is correct |
13 | Correct | 6 ms | 9712 KB | Output is correct |
14 | Correct | 5 ms | 9684 KB | Output is correct |
15 | Incorrect | 5 ms | 9684 KB | Output isn't correct |
16 | Halted | 0 ms | 0 KB | - |