Submission #291342

# Submission time Handle Problem Language Result Execution time Memory
291342 2020-09-05T07:28:29 Z muhammad_hokimiyon Painting Walls (APIO20_paint) C++14
0 / 100
2 ms 2688 KB
#include "paint.h"
#include <bits/stdc++.h>

#define fi first
#define se second
#define ll long long
#define dl double long

using namespace std;

vector < int > v[100100];

int minimumInstructions( int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B)
{
    for( int i = 0; i < M; i++ ){
        for( int j = 0; j < A[i]; j++ ){
            int x = B[i][j];
            v[x].push_back(i);
        }
    }
    vector < int > len;
    vector < vector < int > > d( N + 1 , vector < int > ( M , 1e9 ) );
    for( int i = N - 1; i >= 0; i-- ){
        for( auto x : v[C[i]] ){
            if( d[i + 1][(x + 1) % M] != 1e9 ){
                d[i][x] = d[i + 1][(x + 1) % M];
            }else d[i][x] = i;
            if( d[i][x] - i + 1 >= M )len.push_back(i);
        }
    }
    sort( len.begin() , len.end() );
    len.erase( unique( len.begin() , len.end() ) , len.end() );
    int ans = 0 , st = -1;
    for( int i = 0; i < (int)len.size(); i++ ){
        int l = 0 , r = (int)len.size() - 1;
        while( l < r ){
            int m = (l + r) / 2;
            if( len[m + 1] > st + 1 )r = m;
            else l = m + 1;
        }
        if( st == N - 1 )break;
        if( len[l] > st + 1 || len[l] + M - 1 <= st ){
            return -1;
        }
        st = len[l] + M - 1;
        ans += 1;
    }
    return ans;
}
# 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 Incorrect 2 ms 2688 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Incorrect 2 ms 2688 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Incorrect 2 ms 2688 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Incorrect 2 ms 2688 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Incorrect 2 ms 2688 KB Output isn't correct