Submission #963985

# Submission time Handle Problem Language Result Execution time Memory
963985 2024-04-16T07:09:30 Z efedmrlr Painting Walls (APIO20_paint) C++17
0 / 100
1 ms 348 KB
// #pragma GCC optimize("O3,Ofast,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#include "paint.h"

using namespace std;


#define lli long long int

#define MP make_pair
#define pb push_back
#define REP(i,n) for(int i = 0; (i) < (n); (i)++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()


void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}


const double EPS = 0.00001;
const int INF = 1e9+500;
const int ALPH = 26;
const int LGN = 25;
constexpr int MOD = 1e9+7;

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

    vector<vector<int> > col(K, vector<int>());
    vector<array<int,2> > dp, dpn;
    vector<int> mx(N, 0);

    swap(A, C);
    // for(auto c : A) {
    //     cout << c << " ";
    // }
    // cout << endl;
    for(int i = 0; i < M; i++) {
        for(auto c : B[i]) {
            col[c].pb(i);
        }
    }
    for(int i = 0; i < N; i++) {
        for(auto c : col[A[i]]) {
            auto itr = lower_bound(all(dp), array<int,2>({(c == 0 ? M - 1 : c - 1), 0})) - dp.begin();
            if(itr >= dp.size() || dp[itr][0] != (c == 0 ? M - 1 : c - 1)) {
                mx[i] = max(mx[i], 1);
                dpn.pb({c, 1});
            }
            else {
                mx[i] = max(mx[i], dp[itr][1] + 1);
                dpn.pb({c, dp[itr][1] + 1});
            }
        }
        swap(dp, dpn);
        dpn.clear();
    }
    vector<int> vals;
    for(int i = 0; i < N; i++) {
        if(mx[i] >= M) {
            vals.pb(i);
        }
    }
    // for(auto c : vals) {
    //     cout << c << " ";
    // }
    // cout << endl;
    int bor = M - 1;
    int ans = 0;
    while(bor < M) {
        auto itr = upper_bound(all(vals), bor) - vals.begin();
        itr--;
        if(itr < 0 || vals[itr] <= bor - M) {
            return -1;
        }
        ans++;
        bor = vals[itr] + M;
    }
    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:51:20: warning: comparison of integer expressions of different signedness: 'long int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |             if(itr >= dp.size() || dp[itr][0] != (c == 0 ? M - 1 : c - 1)) {
      |                ~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -