Submission #560682

#TimeUsernameProblemLanguageResultExecution timeMemory
560682ala2Painting Walls (APIO20_paint)C++14
12 / 100
44 ms10196 KiB
#include "paint.h" #include <vector> #include <bits/stdc++.h> #define F first #define S second //#define int long long #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; // cout<<endl; for(int i=0;i<n;i++) { int x=a[i]; if(b[x]==0) return -1; c[i]=b[x]; // cout<<c[i]<<" "; } // cout<<endl; big[0]=1; // cout<<1<<" "; for(int i=1;i<n;i++) { if(c[i]-c[i-1]==1) { big[i]=big[i-1]+1; } else big[i]=1; // cout<<big[1]<<" "; } // cout<<endl; int x=n-m; for(int i=0;i<=x;i++) { if(good(i)) { v.pb(i); } } sort(v.begin(),v.end()); //for(auto i:v) // cout<<i<<" "; // cout<<endl; 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(cur==x) { break; } if(v[i]==x) { ans++; break; } 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; } /* 17 5 6 1 2 3 4 6 1 2 4 6 6 1 2 3 4 6 1 2 1 1 1 2 1 3 1 4 1 6 */

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