Submission #737690

# Submission time Handle Problem Language Result Execution time Memory
737690 2023-05-07T14:46:48 Z Abrar_Al_Samit Painting Walls (APIO20_paint) C++17
0 / 100
10 ms 14652 KB
#include "paint.h"
#include <bits/stdc++.h>
using namespace std;



const int nax = 1e5 + 1;
const int snax = 700;


vector<int> col_to_wall[nax], cand[nax];
vector<int>dp[nax];
bool good[nax];

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

    
    for(int i=0; i<N; ++i) {
        col_to_wall[C[i]].push_back(i);
    }

    for(int i=0; i<M; ++i) {
        for(int j=0; j<A[i]; ++j) {
            for(int x : col_to_wall[B[i][j]]) {
                cand[x].push_back(i);
            }
        }
    }

    for(int i=1; i<=N; ++i) {
        if(i<N) dp[i].assign(cand[i-1].size(), -1);
        else dp[i].assign(cand[i-1].size(), 0);
    }
    for(int i=N-1; i>=1; --i) {
        int ptr = 0;
        for(int j=0; j<cand[i-1].size(); ++j) {
            if(cand[i-1][j]+1==M) {
                if(cand[i][0]==0) {
                    dp[i][j] = 1 + dp[i+1][0];
                } else {
                    dp[i][j] = 0;
                }
                continue;
            }

            while(ptr+1<cand[i].size() && cand[i][ptr+1]<=cand[i-1][j]+1) {
                ++ptr;
            }
            if(cand[i][ptr]==cand[i-1][j]+1) {
                dp[i][j] = 1 + dp[i+1][ptr];
            } else {
                dp[i][j] = 0;
            }
        }
    }

    for(int i=0; i<=N-M; ++i) {
        for(int j=0; j<cand[i].size(); ++j) {
            int cur = 1 + dp[i+1][j];
            if(cur>=M) good[i] = 1;
        }
    }


    if(!good[0]) return -1;
    int last = 0, pending = -1;

    int ans = 1;
    for(int i=1; i<N; ++i) {
        if(good[i]) {
            pending = i;
        }
        if(last+M==i) {
            if(pending==-1) return -1;
            last = pending;
            pending = -1;
            ++ans;
        }
    }
    return ans;
}

Compilation message

paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:38:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         for(int j=0; j<cand[i-1].size(); ++j) {
      |                      ~^~~~~~~~~~~~~~~~~
paint.cpp:48:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |             while(ptr+1<cand[i].size() && cand[i][ptr+1]<=cand[i-1][j]+1) {
      |                   ~~~~~^~~~~~~~~~~~~~~
paint.cpp:60:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |         for(int j=0; j<cand[i].size(); ++j) {
      |                      ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Runtime error 10 ms 14652 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Runtime error 10 ms 14652 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Runtime error 10 ms 14652 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Runtime error 10 ms 14652 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Runtime error 10 ms 14652 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -