# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
301522 | 2020-09-18T03:43:40 Z | Muhammetali | Comparing Plants (IOI20_plants) | C++11 | 0 ms | 0 KB |
#include "plants.h" int h,n,arr[200001]; void init(int k, std::vector<int> r) { h=k; n=sz(r); for (int i=0;i<n;i++) { if(r[i]!=k-1)arr[i]=0; else arr[i]=k-1; } return; } int compare_plants(int x, int y) { if (arr[x]==0) { int g=h-1; int f=x+1; while(f<y && g>=0) { if (arr[f]==0)g=h-1; f++; g--; } if (f+1==y)return 1; } else { int g=h-1; int f=x+1; while(f<y && g>=0) { if (arr[f]==h-1)g=h-1; f++; g--; } if (f+1==y)return -1; } if (arr[y]==h-1) { int g=h-1; int f=y+1; while(f<n && g>=0) { if (arr[f]==h-1)g=h-1; f++; g--; } f=0; while(f<x && g>=0) { if (arr[f]==h-1)g=h-1; f++; g--; } if (f+1==x)return 1; } else { int g=h-1; int f=y+1; while(f<n && g>=0) { if (arr[f]==0)g=h-1; f++; g--; } f=0; while(f<x && g>=0) { if (arr[f]==0)g=h-1; f++; g--; } if (f+1==x)return -1; } return 0; }