Submission #397359

# Submission time Handle Problem Language Result Execution time Memory
397359 2021-05-02T00:09:54 Z rocks03 Painting Walls (APIO20_paint) C++14
0 / 100
1 ms 204 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << ": " << x << " "
#define nl cout << "\n"
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B){
    vector<int> pos[N + 1];
    rep(i, 0, N) pos[C[i]].pb(i);
    vector<int> work[N + 1];
    rep(i, 0, M){
        for(int col : B[i]){
            for(int p : pos[col]){
                work[p].pb(i);
            }
        }
    }
    vector<int> g[N];
    rep(i, 0, N) sort(all(work[i]));
    rep(i, 0, N - 1){
        for(int x : work[i]){
            auto it = lower_bound(all(work[i + 1]), (x + 1) % M);
            if(it != work[i + 1].end()){
                g[i].pb(x);
            }
        }
    }
    rep(i, 0, N){
        sort(all(g[i]));
    }
    vector<pii> vt;
    for(int x : g[0]) vt.pb({x, 0});
    vector<bool> v(N, false);
    rep(y, 1, N){
        vector<pii> v2;
        for(auto [x, old_y] : vt){
            int l = y - old_y, x2 = (x + 1) % M;
            if(l == M - 1){
                v[old_y] = true; continue;
            }
            auto it = lower_bound(all(g[y]), x2);
            if(it != g[y].end() && *it == x2){
                v2.pb({x2, old_y});
            }
        }
        swap(vt, v2);
        if(y + M - 1 < N){
            for(int x : g[y]) vt.pb({x, y});
        }
    }
    if(!v[0]) return -1;
    vector<int> dp(N, INT_MAX);
    dp[0] = 1;
    multiset<int> s, ms[N + 1];
    rep(i, 0, N){
        for(int x : ms[i]){
            s.erase(s.find(x));
        }
        if(SZ(s)){
            dp[i] = *s.begin() + 1;
        }
        if(dp[i] == INT_MAX) return -1;
        if(v[i]){
            s.insert(dp[i]);
            int r = min(N - 1, i + M) + 1;
            ms[r].insert(dp[i]);
            if(i + M - 1 >= N - 1) return dp[i];
        }
    }
    return -1;
}

Compilation message

paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:46:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   46 |         for(auto [x, old_y] : vt){
      |                  ^
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -