답안 #965701

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
965701 2024-04-19T05:41:46 Z Pring 벽 칠하기 (APIO20_paint) C++17
0 / 100
1 ms 2496 KB
#include <bits/stdc++.h>
#include "paint.h"
using namespace std;

#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 = 200005, INF = 1e9;
    int n, m, k;
    vector<int> c;
    vector<vector<int>> clr;

    int cid[MXN], worker[MXN];
    bitset<MXN> b, bb;
    int dp[MXN];

    int miku() {
        FOR(i, 0, m) {
            fill(cid + 1, cid + k + 1, -1);
            assert(clr[i].size() == 1);
            cid[clr[i][0]] = i;
        }
        FOR(i, 0, n) {
            if (cid[c[i]] == -1) return -1;
            worker[i] = cid[c[i]];
        }
        FOR(i, 1, n) if ((worker[i - 1] + 1) % m == worker[i]) b[i] = true;
        int cnt = 0;
        FOR(i, 1, m) cnt += b[i];
        bb[m] = (cnt == m - 1);
        FOR(i, m, n) {
            cnt += b[i];
            cnt -= b[i - m + 1];
            bb[i + 1] = (cnt == m - 1);
        }
        deque<pii> dq;
        dp[0] = 0;
        dq.push_back(mp(0, 0));
        FOR(i, 1, n + 1) {
            if (!bb[i]) {
                dp[i] = INF;
                continue;
            }
            while (dq.size() && dq.front().sc < i - m) dq.pop_front();
            if (dq.empty()) return -1;
            dp[i] = 1 + dq.front().fs;
            debug(i);
            // for (auto &j : dq) cout << j.fs << ' ' << j.sc << endl;
            while (dq.size() && dq.back().fs >= dp[i]) dq.pop_back();
            dq.push_back(mp(dp[i], i));
        }
        // FOR(i, 1, n + 1) cout << dp[i] << ' ';
        // cout << endl;
        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;
    ::c = C;
    ::clr = B;
    return miku();
}

Compilation message

paint.cpp: In function 'int {anonymous}::miku()':
paint.cpp:12:20: warning: statement has no effect [-Wunused-value]
   12 | #define debug(...) 39
      |                    ^~
paint.cpp:62:13: note: in expansion of macro 'debug'
   62 |             debug(i);
      |             ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2496 KB Output is correct
3 Incorrect 1 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2496 KB Output is correct
3 Incorrect 1 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2496 KB Output is correct
3 Incorrect 1 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2496 KB Output is correct
3 Incorrect 1 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2496 KB Output is correct
3 Incorrect 1 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -