Submission #289372

# Submission time Handle Problem Language Result Execution time Memory
289372 2020-09-02T15:42:03 Z beso123 Painting Walls (APIO20_paint) C++14
Compilation error
0 ms 0 KB
#include "paint.h"
#include <bits/stdc++.h>
#define int long long
using namespace std;
int minimumInstructions(int n,int m,int s,vector<int> col,vector<int> Size,vector<vector<int>> b){
    vector<int> mp[s+1];
    for(int k=0;k<m;k++){
        for(int i=0;i<Size[k];i++){
            mp[b[k][i]].push_back(k);
        }
    }
    deque<int> v;
    v.resize(m,0);
    for(int k=0;k<m;k++){
        for(int i=0;i<mp[col[k]].size();i++){
            int nom=mp[col[k]][i];
            nom=((nom-k)+m)%m;
            v[nom]++;
        }
    }
    vector<int> a(n,0);
    for(int k=0;k<v.size();k++)
        if(v[k]==m)
            a[m-1]++;
    for(int k=m;k<n;k++){
        int cl=col[k-m];
        for(int i=0;i<mp[cl].size();i++){
            v[mp[cl][i]]--;
        }
        cl=col[k];
        int x=v[v.size()-1];
        v.pop_back();
        v.push_front(x);
        for(int i=0;i<mp[cl].size();i++){
            v[(mp[cl][i]+1)%m]++;
           if(v[(mp[cl][i]+1)%m]==m)
            a[k]++;
        }
    }
    int ans=0;
    vector<int> w(n+1,-1);
    if(a[m-1]==1)
        w[m-1]=m-1;
    for(int k=m;k<n;k++){
        w[k]=w[k-1];
        if(a[k]==1)
            w[k]=k;
    }
    int j=m-1;
    while(true){
        if(w[j]==-1)
            return -1;
            ans++;
            if(j==n-1)
                break;
        int i=(j+m);
        if(i>=n)
            i=n-1;
        if(w[i]==w[j])
            return -1;
        j=w[i];
    }
    return ans;

}

Compilation message

paint.cpp: In function 'long long int minimumInstructions(long long int, long long int, long long int, std::vector<long long int>, std::vector<long long int>, std::vector<std::vector<long long int> >)':
paint.cpp:15:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |         for(int i=0;i<mp[col[k]].size();i++){
      |                     ~^~~~~~~~~~~~~~~~~~
paint.cpp:22:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::deque<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for(int k=0;k<v.size();k++)
      |                 ~^~~~~~~~~
paint.cpp:27:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |         for(int i=0;i<mp[cl].size();i++){
      |                     ~^~~~~~~~~~~~~~
paint.cpp:34:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         for(int i=0;i<mp[cl].size();i++){
      |                     ~^~~~~~~~~~~~~~
paint.cpp:51:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   51 |         if(w[j]==-1)
      |         ^~
paint.cpp:53:13: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   53 |             ans++;
      |             ^~~
/tmp/cc40MfQz.o: In function `main':
grader.cpp:(.text.startup+0x250): undefined reference to `minimumInstructions(int, int, int, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >)'
collect2: error: ld returned 1 exit status