Submission #333435

# Submission time Handle Problem Language Result Execution time Memory
333435 2020-12-06T00:06:32 Z 534351 Painting Walls (APIO20_paint) C++17
0 / 100
2 ms 2668 KB
#include "paint.h"
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>

using namespace std;
// using namespace __gnu_pbds;

// template<class T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template<class T, class U>
void ckmin(T &a, U b)
{
    if (a > b) a = b;
}

template<class T, class U>
void ckmax(T &a, U b)
{
    if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

const int MAXN = 100013;
const int INF = 1e9 + 7;

int N, M, K; //N numbers, M contractors, K colors, each colors supports blah contractors, sum(blah^2) is small
int arr[MAXN];
vi ok[MAXN];
int dp[MAXN];
bitset<MAXN> chk;
multiset<int> dps;
int ans;

int getval(int x)
{
    x %= M;
    if (x < 0) x += M;
    return x;
}
int minimumInstructions(int n, int m, int k, vi C, vi A, vector<vi> B)
{
    N = n;
    M = m;
    K = k;
    copy(ALL(C), arr);
    FOR(i, 0, SZ(A))
    {
        FOR(j, 0, A[i])
        {
            ok[B[i][j]].PB(i);
        }
    }
    FOR(i, 0, N)
    {
        for (int x : ok[arr[i]])
        {
            // cerr << x << ' ' << getval(x - i) << endl;
            dp[getval(x - i)]++;
        }
        if (i >= M)
        {
            for (int x : ok[arr[i - M]])
            {
                dp[getval(x - i)]--;
            }
        }
        for (int x : ok[arr[i]])
        {
            if (dp[getval(x - i)] == M)
            {
                chk[i] = true;
                // cerr << "CHK " << i << endl;
            }
        }
    }
    if (!chk[M - 1])
    {
        return -1;
    }
    fill(dp, dp + M, INF);
    dp[M - 1] = 1;
    FOR(i, 0, M)
    {
        dps.insert(dp[i]);
    }
    FOR(i, M, N)
    {
        dp[i] = (chk[i] ? *dps.begin() + 1 : INF);
        dps.insert(dp[i]);
        dps.erase(dps.find(dp[i - M]));
    }
    ans = dp[N - 1];
    if (ans == INF) ans = -1;
    return ans;
    //now find min taht's checkable.
    // FOR(i, 0, n)
    // {
    //     for (int x : ok[arr[i]])
    //     {
    //         cerr << x << ' ';
    //     }
    //     cerr << endl;
    // }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 2 ms 2668 KB Output is correct
9 Incorrect 2 ms 2668 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 2 ms 2668 KB Output is correct
9 Correct 2 ms 2668 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Incorrect 2 ms 2668 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 2 ms 2668 KB Output is correct
9 Correct 2 ms 2668 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Incorrect 2 ms 2668 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 2 ms 2668 KB Output is correct
9 Correct 2 ms 2668 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Incorrect 2 ms 2668 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 2 ms 2668 KB Output is correct
9 Correct 2 ms 2668 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Incorrect 2 ms 2668 KB Output isn't correct
12 Halted 0 ms 0 KB -