답안 #291342

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
291342 2020-09-05T07:28:29 Z muhammad_hokimiyon 벽 칠하기 (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;
}
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Incorrect 2 ms 2688 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Incorrect 2 ms 2688 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Incorrect 2 ms 2688 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Incorrect 2 ms 2688 KB Output isn't correct