Submission #502677

#TimeUsernameProblemLanguageResultExecution timeMemory
502677Sad_BusWatching (JOI13_watching)C++14
50 / 100
1087 ms32080 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; long long get_rand() { long long a = rand(); long long b = rand(); return a * (RAND_MAX + 1ll) + b; } #define int long long #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> #define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> #define intmin -100000000000000000LL #define intmax 100000000000000000LL vector<int> arr; int n, p, q; bool check(int m){ //I will require total at most n cameras vector<vector<int>> dp(n+2, vector<int>(n+2, 0)); //position, small cameras, will be at most n for (int i = 1; i <= n; ++i) { int sOne = lower_bound(arr.begin(), arr.end(), arr[i]-(2*m)+1) - arr.begin(); dp[i][0] = dp[max(0LL, sOne-1)][0] + 1; for (int j = 1; j <= min(p, i); ++j) //use those many small cameras max { //first position behind ith with diff <= m, aka use a small camera; int one = lower_bound(arr.begin(), arr.end(), arr[i]-m+1) - arr.begin() - 1; one = max(0LL, one); //first position behind ith with diff <= 2*m, aka use a big camera; int two = lower_bound(arr.begin(), arr.end(), arr[i]-(m*2)+1) - arr.begin() - 1; two = max(0LL, two); dp[i][j] = min(dp[one][j-1], dp[two][j]+1); } } for (int i = 0; i <= min(p, n); ++i) { if(dp[n][i] <= q){ return true; } } return false; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> p >> q; arr.assign(n+1, 0); arr[0] = 0; for (int i = 1; i <= n; ++i) { cin >> arr[i]; } sort(arr.begin(), arr.end()); int l = 0, r = 10000000000, mid = (l+r)/2, ans; while(l <= r){ mid = (l+r)/2; if(check(mid)){ ans = mid; r = mid - 1; } else{ l = mid + 1; } } cout << max(ans, 1LL) << '\n'; }

Compilation message (stderr)

watching.cpp: In function 'int32_t main()':
watching.cpp:70:48: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   70 |     int l = 0, r = 10000000000, mid = (l+r)/2, ans;
      |                                                ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...