Submission #813713

#TimeUsernameProblemLanguageResultExecution timeMemory
813713LIFRadio Towers (IOI22_towers)C++17
0 / 100
4035 ms2256 KiB
#include "towers.h" #include <vector> #include<bits/stdc++.h> using namespace std; int n; pair <int,int> aa[300005]; int bb[300005]; void init(int N, std::vector<int> H) { n = N; for(int i=0;i<H.size();i++) { aa[i+1].first = H[i]; aa[i+1].second = i+1; bb[i+1] = H[i]; } sort(aa+1,aa+n+1); return; } bool choose[300005]; int max_towers(int L, int R, int D) { int ans = 0; for(int i=1;i<=n;i++)choose[i] = false; for(int i=1;i<=n;i++) { int xx = aa[i].second; int leftmax = -1; bool flag = true; for(int j=xx-1;j>=1;j--) { if(choose[j] == false) { leftmax = max(leftmax,bb[j]); } else { if(bb[j] <= leftmax - D && bb[xx] <= leftmax - D)continue; else { // cout<<xx<<" "<<j<<" "<<leftmax<<endl; flag = false; break; } } //cout<<endl; } int rightmax = -1; for(int j=xx+1;j<=n;j++) { if(choose[j] == false) { //cout<<aa[j].first<<" "; rightmax = max(rightmax,bb[j]); } else { if(bb[j] <= rightmax - D && bb[xx] <= rightmax - D)continue; else { // cout<<xx<<" "<<j<<rightmax<<endl; flag = false; break; } } //cout<<endl; } if(flag == true) { //cout<<xx<<endl; ans++; choose[xx] = true; } } return ans; }

Compilation message (stderr)

towers.cpp: In function 'void init(int, std::vector<int>)':
towers.cpp:10:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |  for(int i=0;i<H.size();i++)
      |              ~^~~~~~~~~
#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...