Submission #1065830

#TimeUsernameProblemLanguageResultExecution timeMemory
1065830j_vdd16Radio Towers (IOI22_towers)C++17
14 / 100
681 ms2040 KiB
#include "towers.h" #include <algorithm> #include <bitset> #include <cstdint> #include <cstring> #include <iostream> #include <limits.h> #include <math.h> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> //#define int long long #define loop(X, N) for(int X = 0; X < (N); X++) #define all(V) V.begin(), V.end() #define rall(V) V.rbegin(), V.rend() using namespace std; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<vector<ii>> vvii; typedef vector<bool> vb; typedef vector<vector<bool>> vvb; typedef uint64_t u64; typedef int64_t i64; int n; vi h; vi minPref; int getMax(int l, int r) { int best = 0; for (int i = l; i <= r; i++) { best = max(best, h[i]); } return best; } void init(int N, std::vector<int> H) { //all H[i] are different //dp[i] = max of 1 and all dp[j] over j s.t. j < i && maxH(j, i) - D >= max(H[i], H[j]) //D = 1 //H = 1, 2, 6, 4, 5, 3, 7 //dp= 1, 1, 1, 2, 2, 3, 1 n = N; h = H; if (n == 1) return; vb isMinimum(n); loop(i, n) { if (i == 0) { isMinimum[i] = h[i] < h[i + 1]; } else if (i == n - 1) { isMinimum[i] = h[i] < h[i - 1]; } else { isMinimum[i] = h[i] < h[i + 1] && h[i] < h[i - 1]; } } minPref = vi(n + 1); for (int i = 1; i < n; i++) { minPref[i + 1] = minPref[i] + isMinimum[i]; } } int max_towers(int L, int R, int D) { if (L == R) { return 1; } int res = minPref[R] - minPref[L + 1]; if (L + 1 < n) { res += h[L] < h[L + 1]; } else { res++; } if (R - 1 >= 0) { res += h[R] < h[R - 1]; } else { res++; } return res; // vi dp(n); // int res = 0; // for (int i = L; i <= R; i++) { // dp[i] = 1; // for (int j = L; j < i; j++) { // if (getMax(j + 1, i - 1) - D >= max(h[i], h[j])) { // dp[i] = max(dp[i], dp[j] + 1); // } // } // res = max(res, dp[i]); // } // 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...