답안 #1029860

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1029860 2024-07-21T12:41:41 Z _8_8_ 벽 칠하기 (APIO20_paint) C++17
0 / 100
12 ms 23924 KB
#include "paint.h"

#include <bits/stdc++.h>

using namespace std;
const int N = 1e6 + 13;
vector<int> v[N];
int dp[N],n,lst[N],val[N];
int minimumInstructions(int nn, int m, int k,vector<int> C,vector<int> A,vector<vector<int>> B) {
    n = nn;
    for(int i = 0;i < m;i++){
        for(int j:B[i]){
            v[j].push_back(i);
        }
    }
    set<int> st;
    const int inf = 1e9;
    st.insert(n);
    for(int i = n - 1;i >= 0;i--){
        bool ok = false;
        for(int j:v[C[i]]){
            int nx = j + 1;
            if(j + 1==m) nx = 0;
            if(lst[nx] == i + 1){
                val[j] = val[nx] + 1;
            }else{
                val[j] = 1;
            }
            if(val[j] >= m){
                ok = true;
            }
            lst[j] = i;
            // cout << j << ' ' << val[j] << "x\n";
        }
        // cout << i << ' ' << ok << '\n';
        // continue;
        if(ok){
            st.insert(i);
        }else{
            dp[i] =inf;
            continue;
        }
        auto it = st.upper_bound(i + m);
        if(it == st.begin()){
            dp[i] = inf;continue;
        }
        it--;
        dp[i] = dp[*it] + 1;
        // cout << i << ' ' << dp[i] << '\n';
    }
    return (dp[0] != inf? dp[0]:-1);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23900 KB Output is correct
2 Correct 10 ms 23900 KB Output is correct
3 Incorrect 10 ms 23924 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23900 KB Output is correct
2 Correct 10 ms 23900 KB Output is correct
3 Incorrect 10 ms 23924 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23900 KB Output is correct
2 Correct 10 ms 23900 KB Output is correct
3 Incorrect 10 ms 23924 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23900 KB Output is correct
2 Correct 10 ms 23900 KB Output is correct
3 Incorrect 10 ms 23924 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23900 KB Output is correct
2 Correct 10 ms 23900 KB Output is correct
3 Incorrect 10 ms 23924 KB Output isn't correct
4 Halted 0 ms 0 KB -