Submission #1233930

#TimeUsernameProblemLanguageResultExecution timeMemory
1233930antonnRadio Towers (IOI22_towers)C++20
0 / 100
4062 ms1576 KiB
#include "towers.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e5 + 7; int n, a[N]; void init(int N, vector<int> h) { n = N; for (int i = 1; i <= n; ++i) a[i] = h[i - 1]; } int max_towers(int l, int r, int d) { ++l; ++r; int pos = l; for (int i = l + 1; i <= r; ++i) if (a[i] < a[pos]) pos = i; int res = 1; int j = pos - 1, last = pos, mx = 0; while (j >= l) { if (a[j] <= mx - d && a[last] <= mx - d) { last = j; mx = 0; res++; } else { mx = max(mx, a[j]); } --j; } j = pos + 1; last = pos; mx = 0; while (j <= r) { if (a[j] <= mx - d && a[last] <= mx - d) { last = j; mx = 0; res++; } else { mx = max(mx, a[j]); } ++j; } return res; }
#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...