Submission #336159

#TimeUsernameProblemLanguageResultExecution timeMemory
336159duality벽 칠하기 (APIO20_paint)C++11
100 / 100
1186 ms20968 KiB
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

vi poss[100000];
int occ[100000];
vpii adjList[100001];
int dist[100001];
priority_queue<pii> H;
int minimumInstructions(int N,int M,int K,vector<int> C,vector<int> A,vector<vector<int> > B) {
    int i,j;
    for (i = 0; i < M; i++) {
        for (j = 0; j < B[i].size(); j++) poss[B[i][j]].pb(i);
    }
    int c = 0;
    for (i = 0; i < N; i++) {
        int z = i % M;
        for (j = 0; j < poss[C[i]].size(); j++) {
            int x = poss[C[i]][j]-z;
            if (x < 0) x += M;
            if (occ[x] == M) c--;
            occ[x]++;
            if (occ[x] == M) c++;
        }
        if (i >= M) {
            for (j = 0; j < poss[C[i-M]].size(); j++) {
                int x = poss[C[i-M]][j]-z;
                if (x < 0) x += M;
                if (occ[x] == M) c--;
                occ[x]--;
                if (occ[x] == M) c++;
            }
        }
        if (c > 0) adjList[i-M+1].pb(mp(i+1,1));
        adjList[i+1].pb(mp(i,0));
    }
    fill(dist,dist+N+1,-1);
    dist[0] = 0,H.push(mp(0,0));
    while (!H.empty()) {
        int u = H.top().second;
        int d = -H.top().first;
        H.pop();

        if (d > dist[u]) continue;
        for (i = 0; i < adjList[u].size(); i++) {
            int v = adjList[u][i].first;
            if ((dist[v] == -1) || (d+adjList[u][i].second < dist[v])) {
                dist[v] = d+adjList[u][i].second;
                H.push(mp(-dist[v],v));
            }
        }
    }
    return dist[N];
}

Compilation message (stderr)

paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:66:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |         for (j = 0; j < B[i].size(); j++) poss[B[i][j]].pb(i);
      |                     ~~^~~~~~~~~~~~~
paint.cpp:71:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |         for (j = 0; j < poss[C[i]].size(); j++) {
      |                     ~~^~~~~~~~~~~~~~~~~~~
paint.cpp:79:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |             for (j = 0; j < poss[C[i-M]].size(); j++) {
      |                         ~~^~~~~~~~~~~~~~~~~~~~~
paint.cpp:98:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |         for (i = 0; i < adjList[u].size(); i++) {
      |                     ~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...