Submission #967835

# Submission time Handle Problem Language Result Execution time Memory
967835 2024-04-23T01:33:13 Z Pring Painting Walls (APIO20_paint) C++17
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>
#include <bits/extc++.h>
#include "paint.h"
using namespace std;
using namespace __gnu_pbds;
 
#ifdef MIKU
string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif
 
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
using ll = long long;
typedef pair<int, int> pii;
 
namespace {
    const int MXN = 100005, INF = 1e9;
    int n, m, k;
    vector<int> c;
    vector<vector<int>> clr;
    vector<vector<int>> ava;
    gp_hash_table<int, int> M[2];
    bitset<MXN> b;
    int dp[MXN];
    deque<pii> dq;
 
    int miku() {
        ava.resize(k);
        FOR(i, 0, m) {
            for (auto &j : clr[i]) ava[j].push_back(i);
        }
        for (auto &i : ava[c[n - 1]]) M[(n - 1) & 1][i] = 1;
        for (auto [x, y] : M[1]) if (y >= m) b[n - 1] = true;
        for (int i = n - 2; i >= 0; i--) {
            int now = (i & 1);
            int pre = (now ^ 1);
            for (auto &j : ava[c[i]]) {
                M[now][j] = M[pre][j == m - 1 ? 0 : j + 1] + 1;
                if (M[now][j] >= m) b[i] = true;
            }
            M[pre].clear();
        }
        b = b << m;
        dp[0] = 0;
        dq.push_back(mp(0, 0));
        FOR(i, 1, n + 1) {
            while (dq.size() && dq.front().sc < i - m) dq.pop_front();
            dp[i] = dq.front().fs + 1;
            if (!b[i]) dp[i] = INF;
            while (dq.size() && dq.back().fs >= dp[i]) dq.pop_back();
            dq.push_back(mp(dp[i], i));
        }
        FOR(i, 0, n + 1) debug(i, dp[i]);
        return (dp[n] >= INF ? -1 : dp[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;
    c = C;
    clr = B;
    return miku();
}

Compilation message

paint.cpp: In function 'int {anonymous}::miku()':
paint.cpp:14:20: warning: statement has no effect [-Wunused-value]
   14 | #define debug(...) 39
      |                    ^~
paint.cpp:61:26: note: in expansion of macro 'debug'
   61 |         FOR(i, 0, n + 1) debug(i, dp[i]);
      |                          ^~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -