답안 #597374

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
597374 2022-07-16T00:15:35 Z Ozy 벽 칠하기 (APIO20_paint) C++17
0 / 100
551 ms 524288 KB
#include "paint.h"
#include<bits/stdc++.h>
using namespace std;
#define lli int
#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define repa(i,a,b) for (int i = (a); i >= (b); i--)
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "

#define MAX 100000

lli n,m,k,res,pos,mejor,dif,a,last,b,otro,ult;
//valores de 0 a m
lli dp[MAX+2][1002];
lli top[MAX+2];
//checar memoria
vector<lli> colores[MAX+2];

int minimumInstructions(int N, int M, int K, std::vector<int> C,std::vector<int> A, std::vector<std::vector<int>> B) {
    n = N;
    m = M;
    k = K;

    rep(i,0,m-1) {
        rep(j,0,A[i]-1) {
            colores[B[i][j]].push_back(i);
        }
    }

    rep(i,0,colores[C[n-1]].size()-1) dp[n-1][i] = 1;
    top[n-1] = 1;

    repa(i,n-2,0) {
        top[i] = 0;
        a = 0;
        b = 0;
        for(auto act : colores[C[i]]) {
            while (b < colores[C[i+1]].size() && colores[C[i+1]][b] < (act+1)) b++;

            if (b < colores[C[i+1]].size() && colores[C[i+1]][b] == (act+1)) dp[i][a] = dp[i+1][b] + 1;
            else dp[i][a] = 1;

            if (dp[i][a] > m) dp[i][a] = m;
            top[i] = max(top[i], dp[i][a]);

            a++;
        }
        //caso especial de overlaping
        ult = colores[ C[i] ].size() - 1;
        if (colores[C[i]][ ult ] == m-1 && colores[C[i+1]][0] == 0) {
            dp[i][ult] = dp[i+1][0] + 1;
            if(dp[i][ult] > m) dp[i][ult] = m;
            top[i] = max(top[i], dp[i][ult]);
        }

    }

    if (top[0] < m) return -1;
    pos = m;
    last = 0;
    res = 1;

    rep(i,1,n-1) {
        if (top[i] == m) last = i;
        if (i == pos) {
            pos = last + m;
            res++;
        }
    }

    if (pos < n) return -1;
    else return res;
}

Compilation message

paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:5:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define rep(i,a,b) for (int i = (a); i <= (b); i++)
      |                                        ^
paint.cpp:30:5: note: in expansion of macro 'rep'
   30 |     rep(i,0,colores[C[n-1]].size()-1) dp[n-1][i] = 1;
      |     ^~~
paint.cpp:38:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |             while (b < colores[C[i+1]].size() && colores[C[i+1]][b] < (act+1)) b++;
      |                    ~~^~~~~~~~~~~~~~~~~~~~~~~~
paint.cpp:40:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |             if (b < colores[C[i+1]].size() && colores[C[i+1]][b] == (act+1)) dp[i][a] = dp[i+1][b] + 1;
      |                 ~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2660 KB Output is correct
3 Runtime error 551 ms 524288 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2660 KB Output is correct
3 Runtime error 551 ms 524288 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2660 KB Output is correct
3 Runtime error 551 ms 524288 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2660 KB Output is correct
3 Runtime error 551 ms 524288 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2660 KB Output is correct
3 Runtime error 551 ms 524288 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -