Submission #560679

#TimeUsernameProblemLanguageResultExecution timeMemory
560679ala2Painting Walls (APIO20_paint)C++14
0 / 100
1 ms692 KiB
#include "paint.h" #include <vector> #include <bits/stdc++.h> #define F first #define S second #define pb push_back using namespace std; int a[1001000]; int b[1001000]; int c[1001000]; int big[1001000]; int n,m; int good(int i) { int x=c[i]; int dis=m-x+i; if(c[dis]!=m) return 0; if(big[dis]<m-x+1) { return 0; } if(x==1) return 1; int nw=dis+1; int bag=nw+x-2; if(c[nw]!=1) return 0; if(c[bag]!=x-1) return 0; if(big[bag]<x-1) return 0; return 1; } vector<int>v; 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++) { a[i]=C[i]; } for(int i=0;i<B.size();i++) { for(int j=0;j<B[i].size();j++) { b[B[i][j]]=i+1; } } //int bb=0; for(int i=0;i<n;i++) { int x=a[i]; if(b[x]==0) return -1; c[i]=b[x]; } big[0]=1; for(int i=1;i<n;i++) { if(a[i]-a[i-1]==1) { big[i]=big[i-1]+1; } else big[i]=1; } int x=n-m; for(int i=0;i<=x;i++) { if(good(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; } 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]; } } if(bb) return -1; return ans; }

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:43:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for(int i=0;i<C.size();i++)
      |                 ~^~~~~~~~~
paint.cpp:47:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for(int i=0;i<B.size();i++)
      |                 ~^~~~~~~~~
paint.cpp:49:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         for(int j=0;j<B[i].size();j++)
      |                     ~^~~~~~~~~~~~
paint.cpp:91:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |     for(int i=1; i<v.size(); i++)
      |                  ~^~~~~~~~~
paint.cpp:103:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |     for(int i=1; i<v.size(); i++)
      |                  ~^~~~~~~~~
paint.cpp:106:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |         if(i==v.size()-1)
      |            ~^~~~~~~~~~~~
#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...