Submission #629454

#TimeUsernameProblemLanguageResultExecution timeMemory
629454handlenameRadio Towers (IOI22_towers)C++17
27 / 100
4074 ms1488 KiB
#include <bits/stdc++.h> #include "towers.h" using namespace std; #define pb push_back #define mp make_pair int n,arr[100001]; int k; void init(int N,vector<int> H){ n=N; for (int i=1;i<=n;i++){ arr[i]=H[i-1]; } k=1; while (k<=n && arr[k+1]>arr[k]){ k++; } for (int i=k+1;i<=n;i++){ if (arr[i]>arr[i-1]){ k=-1; } } } int max_towers(int l,int r,int d){ l++; r++; if (k!=-1){ if (l>=k || r<=k) return 1; if (arr[l]<=arr[k]-d && arr[r]<=arr[k]-d) return 2; return 1; } int ans=1,smol=arr[l],tall=arr[l]; for (int i=l+1;i<=r;i++){ if (tall<smol+d){ smol=min(smol,arr[i]); tall=arr[i]; } tall=max(tall,arr[i]); if (tall>=smol+d && tall>=arr[i]+d){ smol=arr[i]; tall=arr[i]; ans++; } } return ans; }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...