Submission #410354

#TimeUsernameProblemLanguageResultExecution timeMemory
410354Carmel_Ab1Painting Walls (APIO20_paint)C++17
0 / 100
1585 ms8340 KiB
#include <bits/stdc++.h>
#include "paint.h"

//#include "grader.cpp"

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define all(x) x.begin(),x.end()
#define pb push_back
#define umap unordered_map

int minimumInstructions(int N, int M, int K, vi C,vi A, vvi B) {
    for(int i=0; i<B.size(); i++)
        sort(all(B[i]));

    vi cur(M),nxt(M);

    set<int>segs;
    for(int j=0; j<M; j++){
        nxt[j]=0;
        for(int j2=0; j2<M;nxt[j]++,j2++)
            if(!binary_search(all(B[(j+j2)%M]),C[(N-M+j2)]))
                break;
        if(nxt[j])
            segs.insert(N-M);
    }
    for(int i=N-M-1; 0<=i;i--){
        for(int j=0; j<M; j++){
            if(!binary_search(all(B[j]),C[i]))continue;

            cur[j]=min(M,nxt[(j+1)%M]+1);
            if(cur[j]==M)
                segs.insert(i);
        }
        for(int j=0; j<M; j++)
            nxt[j]=cur[j],cur[j]=0;
    }

    int ans=0;
    vector<bool>cov(N);

    for(int i=0; i<N;i++){
        if(cov[i])continue;
        int l=-1;
        for(int j=0;i-j>=0 && j<M; j++)
            if(segs.count(i-j)) {
                l = i - j;
                break;
            }
        if(l==-1)return -1;
        for(int j=l; j<l+M; j++)
            cov[j]=1;
        ans++;
    }
    return ans;

}

Compilation message (stderr)

paint.cpp: In function 'int minimumInstructions(int, int, int, vi, vi, vvi)':
paint.cpp:15:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for(int i=0; i<B.size(); i++)
      |                  ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...