# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
935194 | 2024-02-28T19:23:24 Z | MinaRagy06 | Painting Walls (APIO20_paint) | C++17 | 6 ms | 12088 KB |
#include <bits/stdc++.h> #ifdef MINA #include "grader.cpp" #endif #include "paint.h" using namespace std; #define ll long long const int N = 100'005, M = 50'005; vector<int> gud[N + M + 5]; vector<int> col[M]; int ptr1[N + M + 5], ptr2[N + M + 5]; int minimumInstructions(int n, int m, int K, vector<int> a, vector<int> sz, vector<vector<int>> b) { for (int i = 0; i < m; i++) { for (auto j : b[i]) { col[j].push_back(i); } } for (int i = 0; i < n; i++) { for (auto j : col[a[i]]) { gud[i - j + M].push_back(i); } } // for (int i = -m; i < n; i++) { // // } int dp[n + 1]{}; dp[n] = 0; for (int i = n - 1; i > n - m; i--) { dp[i] = 1e9; } multiset<int> cur; for (int i = n - m + 2; i <= n; i++) { cur.insert(dp[i]); } for (int i = n - m; i >= 0; i--) { cur.insert(dp[i + 1]); if (i + m + 1 <= n) { cur.erase(cur.find(dp[i + m + 1])); } dp[i] = 1e9; bool ok = 0; for (auto j : col[a[i]]) { bool ok2 = 1; int st = i + m - j; int s = lower_bound(gud[i - j + M].begin(), gud[i - j + M].end(), i) - gud[i - j + M].begin(); int e = lower_bound(gud[i - j + M].begin(), gud[i - j + M].end(), st - 1) - gud[i - j + M].begin(); ok2 &= e - s + 1 == st - i; ok2 &= e < gud[i - j + M].size() && gud[i - j + M][e] == st - 1 && gud[i - j + M][s] == i; if (st <= i + m - 1) { s = lower_bound(gud[st + M].begin(), gud[st + M].end(), st) - gud[st + M].begin(); e = lower_bound(gud[st + M].begin(), gud[st + M].end(), i + m - 1) - gud[st + M].begin(); ok2 &= e - s + 1 == i + m - st; ok2 &= e < gud[st + M].size() && gud[st + M][e] == i + m - 1 && gud[st + M][s] == st; } ok |= ok2; } if (ok) { dp[i] = *cur.begin() + 1; } } if (dp[0] >= (int)1e9) return -1; return dp[0]; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 5976 KB | Output is correct |
2 | Correct | 1 ms | 5980 KB | Output is correct |
3 | Correct | 2 ms | 5980 KB | Output is correct |
4 | Correct | 2 ms | 5980 KB | Output is correct |
5 | Correct | 1 ms | 5980 KB | Output is correct |
6 | Correct | 1 ms | 5980 KB | Output is correct |
7 | Correct | 2 ms | 5980 KB | Output is correct |
8 | Correct | 2 ms | 5980 KB | Output is correct |
9 | Correct | 2 ms | 5980 KB | Output is correct |
10 | Correct | 2 ms | 5980 KB | Output is correct |
11 | Correct | 2 ms | 5980 KB | Output is correct |
12 | Correct | 2 ms | 5980 KB | Output is correct |
13 | Runtime error | 6 ms | 12088 KB | Execution killed with signal 6 |
14 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 5976 KB | Output is correct |
2 | Correct | 1 ms | 5980 KB | Output is correct |
3 | Correct | 2 ms | 5980 KB | Output is correct |
4 | Correct | 2 ms | 5980 KB | Output is correct |
5 | Correct | 1 ms | 5980 KB | Output is correct |
6 | Correct | 1 ms | 5980 KB | Output is correct |
7 | Correct | 2 ms | 5980 KB | Output is correct |
8 | Correct | 2 ms | 5980 KB | Output is correct |
9 | Correct | 2 ms | 5980 KB | Output is correct |
10 | Correct | 2 ms | 5980 KB | Output is correct |
11 | Correct | 2 ms | 5980 KB | Output is correct |
12 | Correct | 2 ms | 5980 KB | Output is correct |
13 | Runtime error | 6 ms | 12088 KB | Execution killed with signal 6 |
14 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 5976 KB | Output is correct |
2 | Correct | 1 ms | 5980 KB | Output is correct |
3 | Correct | 2 ms | 5980 KB | Output is correct |
4 | Correct | 2 ms | 5980 KB | Output is correct |
5 | Correct | 1 ms | 5980 KB | Output is correct |
6 | Correct | 1 ms | 5980 KB | Output is correct |
7 | Correct | 2 ms | 5980 KB | Output is correct |
8 | Correct | 2 ms | 5980 KB | Output is correct |
9 | Correct | 2 ms | 5980 KB | Output is correct |
10 | Correct | 2 ms | 5980 KB | Output is correct |
11 | Correct | 2 ms | 5980 KB | Output is correct |
12 | Correct | 2 ms | 5980 KB | Output is correct |
13 | Runtime error | 6 ms | 12088 KB | Execution killed with signal 6 |
14 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 5976 KB | Output is correct |
2 | Correct | 1 ms | 5980 KB | Output is correct |
3 | Correct | 2 ms | 5980 KB | Output is correct |
4 | Correct | 2 ms | 5980 KB | Output is correct |
5 | Correct | 1 ms | 5980 KB | Output is correct |
6 | Correct | 1 ms | 5980 KB | Output is correct |
7 | Correct | 2 ms | 5980 KB | Output is correct |
8 | Correct | 2 ms | 5980 KB | Output is correct |
9 | Correct | 2 ms | 5980 KB | Output is correct |
10 | Correct | 2 ms | 5980 KB | Output is correct |
11 | Correct | 2 ms | 5980 KB | Output is correct |
12 | Correct | 2 ms | 5980 KB | Output is correct |
13 | Runtime error | 6 ms | 12088 KB | Execution killed with signal 6 |
14 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 5976 KB | Output is correct |
2 | Correct | 1 ms | 5980 KB | Output is correct |
3 | Correct | 2 ms | 5980 KB | Output is correct |
4 | Correct | 2 ms | 5980 KB | Output is correct |
5 | Correct | 1 ms | 5980 KB | Output is correct |
6 | Correct | 1 ms | 5980 KB | Output is correct |
7 | Correct | 2 ms | 5980 KB | Output is correct |
8 | Correct | 2 ms | 5980 KB | Output is correct |
9 | Correct | 2 ms | 5980 KB | Output is correct |
10 | Correct | 2 ms | 5980 KB | Output is correct |
11 | Correct | 2 ms | 5980 KB | Output is correct |
12 | Correct | 2 ms | 5980 KB | Output is correct |
13 | Runtime error | 6 ms | 12088 KB | Execution killed with signal 6 |
14 | Halted | 0 ms | 0 KB | - |