Submission #982684

# Submission time Handle Problem Language Result Execution time Memory
982684 2024-05-14T16:02:18 Z stegatxins0 Painting Walls (APIO20_paint) C++17
0 / 100
1 ms 1368 KB
#include <bits/stdc++.h>
#include "paint.h"
using namespace std;

#ifdef DEBUG
#include "debug.cpp"
#else
#define dbg(...)
#define dbgarr(...)
#endif

// const int mxM = 50001;
// int f[mxM];
//
const int mxN = 1e5+1;
int mp[mxN], ok[mxN];

int minimumInstructions(
    int N, int M, int K, std::vector<int> C,
    std::vector<int> A, std::vector<std::vector<int>> B) {

    memset(mp,0,sizeof(mp));
    memset(ok,0,sizeof(ok));

    // since each contarctor can only like one color, if no of contractor less than no of color,
    // if(M < N)return -1; // NOTE: B might have color not in C

    deque<int> q;

    int curunq = 0;

    for(int i=0; i<N; i++){
        if(i >= M){
            mp[C[i - M]]--;
            if(mp[C[i - M]] == 0){
                curunq--;
            }
            q.pop_back();
        }
        q.push_front(C[i]);
        mp[C[i]]++;
        if(mp[C[i]] <= 1){
            curunq++;
        }
        if(curunq == M)ok[i] = 1;
    }

    dbgarr(ok,N);
    if(!ok[M-1] || !ok[N-1])return -1;

    int jump = 1;

    int p = M-1, tojump;
    while(p < N-1){
        tojump = -1;
        for(int i=min(p+M,N-1); i>=p+1; i--){
            if(ok[i]){
                tojump = i;
                break;
            }
        }
        if(tojump == -1)return -1;

        jump++;
        p = tojump;
        // dbg(p, p+M);

    }


  return jump;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 1 ms 1368 KB Output is correct
3 Incorrect 1 ms 1112 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 1 ms 1368 KB Output is correct
3 Incorrect 1 ms 1112 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 1 ms 1368 KB Output is correct
3 Incorrect 1 ms 1112 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 1 ms 1368 KB Output is correct
3 Incorrect 1 ms 1112 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 1 ms 1368 KB Output is correct
3 Incorrect 1 ms 1112 KB Output isn't correct
4 Halted 0 ms 0 KB -