Submission #560588

# Submission time Handle Problem Language Result Execution time Memory
560588 2022-05-11T17:28:33 Z ala2 Painting Walls (APIO20_paint) C++14
0 / 100
15 ms 23892 KB
#include "paint.h"
#include <vector>
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
using namespace std;
bool mp[20003][2004];
int a[1001000];
vector<int>v;
int n,m;
int mm[1001000];
int vis[1001000];
int good(int i,int j)
{
    for(int k=0; k<m; k++)
    {
        int x=(i+k)%(m);
        int y=j+k;
        if( mp[x][a[y]]==0 )
        {
            //
            // cout<<"    :   "<<x<<"  "<<a[y]<<"  "<<y<<endl;
            return 0;
        }
    }
    return 1;
}
vector<int>ll;
int mk[1001000];
vector<int>co[1001000];
int minimumInstructions(int N, int M, int K, vector<int> C,vector<int> A, vector<vector<int>> B)
{

    n=N;
    m=M;
    for(int i=0;i<C.size();i++)
    {
        if(!vis[C[i]])
        {
            vis[C[i]]=1;
            ll.pb(C[i]);
        }
    }
    for(int i=0; i<B.size(); i++)
    {
        for(int j=0; j<B[i].size(); j++)
        {
           if(!vis[B[i][j]])
        {
            vis[B[i][j]]=1;
            ll.pb(B[i][j]);
        }
        }
    }
    sort(ll.begin(),ll.end());
    for(int i=0;i<ll.size();i++)
    {
        mm[ll[i]]=i;
    }
    for(int i=0; i<C.size(); i++)
    {
        a[i]=mm[C[i]];
    }
    for(int i=0; i<B.size(); i++)
    {
        for(int j=0; j<B[i].size(); j++)
        {
            mp[i][mm[B[i][j]]]=1;
            co[mm[B[i][j]]].pb(i);
        }
    }
    //int ans=0;
    for(int i=0;i<n;i++)
    {
        if(co[a[i]].size()==0)
            continue;
        int x=co[a[i]][0];
        if(good(x,i))
        {
            v.pb(i);
        }
        


    }
        sort(v.begin(),v.end());
    int cur=0;
    int ans=1;
    int bb=0;
    if(v.size()==0)
    {
        return -1;
    }
    if(v[0]!=0)
    {
        return -1;
    }
    for(int i=1; i<v.size(); i++)
    {
        if(v[i]-v[i-1]>m)
            return -1;
    }
    if(n-v[v.size()-1]>m)
        return -1;

 //   if(n==m)
 //   {
 //       return 1;
 //   }
 int x=n-m;
    for(int i=1; i<v.size(); i++)
    {

        if(i==v.size()-1)
        {
            if(v[i]==x)
            {
                ans++;
                break;
            }
            else
            {
                bb=1;
                break;
            }
        }
        if(v[i]-cur>m)
            bb=1;
        if(v[i+1]-cur>m)
        {
            ans++;
            cur=v[i];
        }
    }
 //   while(bb){
 //      int hh=1;     
  //  }
     if(bb)
       return -1;
        
    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:37:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for(int i=0;i<C.size();i++)
      |                 ~^~~~~~~~~
paint.cpp:45:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for(int i=0; i<B.size(); i++)
      |                  ~^~~~~~~~~
paint.cpp:47:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         for(int j=0; j<B[i].size(); j++)
      |                      ~^~~~~~~~~~~~
paint.cpp:57:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |     for(int i=0;i<ll.size();i++)
      |                 ~^~~~~~~~~~
paint.cpp:61:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |     for(int i=0; i<C.size(); i++)
      |                  ~^~~~~~~~~
paint.cpp:65:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |     for(int i=0; i<B.size(); i++)
      |                  ~^~~~~~~~~
paint.cpp:67:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |         for(int j=0; j<B[i].size(); j++)
      |                      ~^~~~~~~~~~~~
paint.cpp:99:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |     for(int i=1; i<v.size(); i++)
      |                  ~^~~~~~~~~
paint.cpp:112:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |     for(int i=1; i<v.size(); i++)
      |                  ~^~~~~~~~~
paint.cpp:115:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |         if(i==v.size()-1)
      |            ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23892 KB Output is correct
2 Correct 15 ms 23764 KB Output is correct
3 Correct 12 ms 23780 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Incorrect 12 ms 23848 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23892 KB Output is correct
2 Correct 15 ms 23764 KB Output is correct
3 Correct 12 ms 23780 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Incorrect 12 ms 23848 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23892 KB Output is correct
2 Correct 15 ms 23764 KB Output is correct
3 Correct 12 ms 23780 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Incorrect 12 ms 23848 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23892 KB Output is correct
2 Correct 15 ms 23764 KB Output is correct
3 Correct 12 ms 23780 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Incorrect 12 ms 23848 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23892 KB Output is correct
2 Correct 15 ms 23764 KB Output is correct
3 Correct 12 ms 23780 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Incorrect 12 ms 23848 KB Output isn't correct
6 Halted 0 ms 0 KB -