답안 #983190

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
983190 2024-05-15T09:10:11 Z vjudge2 벽 칠하기 (APIO20_paint) C++17
0 / 100
1 ms 436 KB
#include "paint.h"
#include <bits/stdc++.h>
using namespace std;

const int inf = 1e9;

int md(int x, int y) {
    return (x % y + y) % y;
}

int minimumInstructions (int n, int m, int k, std::vector<int> a, std::vector<int> SZ, std::vector<std::vector<int>> b) {
    vector<vector<int>> f(k);
    for (int i = 0; i < m; i++) for (int j : b[i]) {
        f[j].push_back(i);
        // cout << j << ' ' << i << '\n';
    }
    deque<pair<int, int>> dq;
    vector<int> cnt(m, 0);
    vector<int> dp(n, 0);
    dq.push_back({0, -1});
    for (int i = 0; i < n; i++) {
        vector<int> goat;
        if (i >= m) for (int j : f[a[i - m]]) --cnt[md(j - i + m, m)];
        for (int j : f[a[i]]) {
            cnt[md(j - i, m)]++;
            if (cnt[md(j - i, m)] == m) goat.push_back(md(j - i, m));
        }
        if (!goat.empty()) {
            // cout << i << '\n';
            // for (int j : goat) cout << j << ' ';
            // cout << '\n';
            while (!dq.empty() && dq.front().second < i - m) dq.pop_front();
            if (i >= m - 1 && !dq.empty()) dp[i] = dq.front().first + 1;
            else dp[i] = inf;
            // older time ones are better
            while (!dq.empty() && dq.back().first > dp[i]) dq.pop_back();
            dq.push_back({dp[i], i});
        } else dp[i] = inf;
        // for (int j = 0; j < m; j++) cout << cnt[j] << ' ';
        // cout << '\n';
        // cout << "dp " << i << " = " << dp[i] << '\n';
    }
    if (dp[n - 1] == inf) return -1;
    return dp[n - 1];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 436 KB Output is correct
10 Incorrect 1 ms 348 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 436 KB Output is correct
10 Incorrect 1 ms 348 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 436 KB Output is correct
10 Incorrect 1 ms 348 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 436 KB Output is correct
10 Incorrect 1 ms 348 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 436 KB Output is correct
10 Incorrect 1 ms 348 KB Output isn't correct
11 Halted 0 ms 0 KB -