Submission #784254

#TimeUsernameProblemLanguageResultExecution timeMemory
784254GordonRemzi007Radio Towers (IOI22_towers)C++17
11 / 100
4094 ms2344 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; vector<int> a; vector<bool> used; vector<pair<int,int>> b; bool srt(pair<int,int> a, pair<int,int> b) { return a.first < b.first; } void init(int n, vector<int> h) { a = h; used = vector<bool>(n, false); b = vector<pair<int,int>>(n); for(int i = 0; i < n; i++) b[i] = {a[i], i}; sort(b.begin(), b.end(), srt); } int max_towers(int l, int r, int d) { int res = 0, f, s; bool ok; used = vector<bool>(a.size(), false); for(int i = 0; i < a.size(); i++) { if(l > b[i].second || r < b[i].second) continue; f = b[i].second, s = b[i].second; ok = true; //find closest left and right a[i] >= a[b[i].second]+d for(; f >= l; f--) { if(used[f]) { ok = false; break; } if(a[f] >= a[b[i].second]+d) break; if(f == l) { f = b[i].second; break; } } for(; s <= r; s++) { if(used[s]) { ok = false; break; } if(a[s] >= a[b[i].second]+d) break; if(s == r) { s = b[i].second; break; } } if(ok) { used[b[i].second] = true; res++; } } return res; }

Compilation message (stderr)

towers.cpp: In function 'int max_towers(int, int, int)':
towers.cpp:24:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for(int i = 0; i < a.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...