Submission #293385

# Submission time Handle Problem Language Result Execution time Memory
293385 2020-09-08T01:41:24 Z daniel920712 Painting Walls (APIO20_paint) C++14
0 / 100
5 ms 5120 KB
#include "paint.h"

#include <vector>
#include <stdio.h>
#include <queue>
#include <unordered_map>
using namespace std;

unordered_map < int , int > r[5];
int rr[100005];
int DP[100005];
int cha[100005];
vector < int > all;
vector < int > how[100005];
int N,M;
queue < pair < int , int > > now;
int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A,vector< vector<int> > B)
{
    int i,j,ok;
    ::N=N;
    ::M=M;

    for(i=0;i<M;i++)  for(j=0;j<A[i];j++) how[B[i][j]].push_back(i);
    for(i=N-1;i>=0;i--)
    {
        rr[i]=-1e9;
        r[i%2].clear();
        for(auto j:how[C[i]])
        {
            r[i][j]=i;
            if(i!=N-1&&r[1-i%2].find((j+1)%M)!=r[1-i%2].end()) r[i%2][j]=max(i,r[1-i%2][(j+1)%M]);
            rr[i]=max(rr[i],r[i%2][j]);
        }

    }
    now.push(make_pair(0,N));
    for(i=N-1;i>=0;i--)
    {
        ok=0;
        DP[i]=1e9;
        while(!now.empty()&&now.front().second-i>M) now.pop();
        if(i+M>N) continue;
        else
        {
            if(rr[i]>=i+M-1)
            {
                if(now.empty()) DP[i]=1e9;
                else
                {
                    DP[i]=now.front().first+1;
                    now.push(make_pair(DP[i],i));
                }
            }
        }
    }
    int t=DP[0];
    if(t>=1000000000) return -1;
    return t;
}

Compilation message

paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:19:13: warning: variable 'ok' set but not used [-Wunused-but-set-variable]
   19 |     int i,j,ok;
      |             ^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Incorrect 2 ms 2688 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 5120 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 5120 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 5120 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 5120 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -