Submission #962827

#TimeUsernameProblemLanguageResultExecution timeMemory
962827simona1230Robots (IOI13_robots)C++17
53 / 100
154 ms65536 KiB
#include <bits/stdc++.h> #include "robots.h" using namespace std; int a,b,t,x[1000000],y[1000000],w[1000000],s[1000000]; bool check(int k) { int idx=t-1; for(int i=a-1;i>=0;i--) { int cnt=0; while(idx>=0&&cnt<k&&w[idx]<x[i]) { idx--; cnt++; } } if(idx==-1)return 1; return 0; } vector<int> va[1000000],vb[1000000]; int used[1000000]; bool smart(int k) { int in=0; for(int i=0;i<a;i++) { int cnt=0; for(int id=0;id<va[i].size();id++) { int j=va[i][id]; if(used[j]!=k) { used[j]=k; cnt++; in++; } if(cnt==k)break; } } for(int i=0;i<b;i++) { int cnt=0; for(int id=0;id<vb[i].size();id++) { int j=vb[i][id]; if(used[j]!=k) { used[j]=k; cnt++; in++; } if(cnt==k)break; } } if(in==t)return 1; return 0; } bool cmpa(int i,int j) { return s[i]>s[j]; } bool cmpb(int i,int j) { return w[i]>w[j]; } int putaway(int A,int B,int T,int X[],int Y[],int W[],int S[]) { a=A; b=B; t=T; for(int i=0;i<a;i++) x[i]=X[i]; for(int i=0;i<b;i++) y[i]=Y[i]; for(int i=0;i<t;i++) w[i]=W[i],s[i]=S[i]; sort(x,x+a); sort(y,y+b); if(a+b==2&&t==2) { if(a==2) { sort(w,w+t); if(x[0]>w[0]&&x[1]>w[1])return 1; if(x[1]>w[1])return 2; return -1; } if(b==2) { sort(s,s+t); if(y[0]>s[0]&&y[1]>s[1])return 1; if(y[1]>s[1])return 2; return -1; } if(x[0]>w[0]&&y[0]>s[1]||x[0]>w[1]&&y[0]>s[0])return 1; if(x[0]<=w[0]&&y[0]<=s[0]||x[0]<=w[1]&&y[0]<=s[1])return -1; return 2; } if(b==0) { sort(w,w+t); int l=1,r=t; int ans=-1; while(l<=r) { int m=(l+r)/2; if(check(m)) { ans=m; r=m-1; } else l=m+1; } return ans; } for(int i=0;i<a;i++) { for(int j=0;j<t;j++) { if(x[i]>w[j])va[i].push_back(j); } sort(va[i].begin(),va[i].end(),cmpa); } for(int i=0;i<b;i++) { for(int j=0;j<t;j++) { if(y[i]>s[j])vb[i].push_back(j); } sort(vb[i].begin(),vb[i].end(),cmpb); } int l=1,r=t; int ans=-1; while(l<=r) { int m=(l+r)/2; if(smart(m)) { ans=m; r=m-1; } else l=m+1; } return ans; }

Compilation message (stderr)

robots.cpp: In function 'bool smart(int)':
robots.cpp:31:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |         for(int id=0;id<va[i].size();id++)
      |                      ~~^~~~~~~~~~~~~
robots.cpp:47:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         for(int id=0;id<vb[i].size();id++)
      |                      ~~^~~~~~~~~~~~~
robots.cpp: In function 'int putaway(int, int, int, int*, int*, int*, int*)':
robots.cpp:105:21: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  105 |         if(x[0]>w[0]&&y[0]>s[1]||x[0]>w[1]&&y[0]>s[0])return 1;
      |            ~~~~~~~~~^~~~~~~~~~~
robots.cpp:106:22: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  106 |         if(x[0]<=w[0]&&y[0]<=s[0]||x[0]<=w[1]&&y[0]<=s[1])return -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...