Submission #780989

#TimeUsernameProblemLanguageResultExecution timeMemory
780989Mouad_oujRadio Towers (IOI22_towers)C++17
Compilation error
0 ms0 KiB
//#include "towers.h" //sub1 #include <bits/stdc++.h> using namespace std; vector<int> he; int k=-1; void init (int n,vector<int> h) { he.resize(n); for(int x=0;x<n;x++) { he[x]=h[x]; if(h[x]>h[x+1] && x!=n && k==-1) k=x; } if(h[n-1]>h[n-2]) k=n-1; } int max_towers(int l, int r, int d) { //if(l==r) //return 1; if(he[n-1]>he[k]-d || he[0]>he[k]-d) return 0; int ml=k,mr=n-1; while(ml!=mr) { int mid=(ml+mr)/2; if(he[mid]>he[k]-d) ml=mid+1; else mr=mid; } int a1=mr,a2=0; ml=0,mr=k; while(ml!=mr) { int mid=(ml+mr)/2; if(he[mid]<he[k]-d) ml=mid+1; else mr=mid; } a2=mr; a2=max(a2,l); a1=min(a1,r); return ((r-a1+1)+(a2-l)); }

Compilation message (stderr)

towers.cpp: In function 'int max_towers(int, int, int)':
towers.cpp:22:11: error: 'n' was not declared in this scope
   22 |     if(he[n-1]>he[k]-d || he[0]>he[k]-d)
      |           ^
towers.cpp:24:17: error: 'n' was not declared in this scope
   24 |     int ml=k,mr=n-1;
      |                 ^