Submission #883181

#TimeUsernameProblemLanguageResultExecution timeMemory
883181MilosMilutinovicSparklers (JOI17_sparklers)C++14
0 / 100
1 ms348 KiB
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k, t;
  cin >> n >> k >> t;
  --k;
  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  auto Check = [&](long long s) {
    vector<vector<bool>> dp(n, vector<bool>(n));
    vector<vector<bool>> was(n, vector<bool>(n));
    function<bool(int, int)> Solve = [&](int L, int R) {
      if (was[L][R]) {
        return dp[L][R];
      }
      was[L][R] = true;
      if (L == R) {
        if (L == k) {
          dp[L][R] = true;
        } else {
          dp[L][R] = false;
        }
        return dp[L][R];
      }
      long long f = t * 1LL * (R - L);
      if (f <= 5e8) {
        f *= 2;
      }
      if (f <= 1e9) {
        f *= s;
      }      
      if ((x[R] - x[L]) <= f) {
        if (Solve(L + 1, R) || Solve(L, R - 1)) {
          dp[L][R] = true;
        }
      }
      return dp[L][R];
    };
    return Solve(0, n - 1);
  };
  long long low = 1, high = 2e9, ans = -1;
  while (low <= high) {
    long long mid = low + high >> 1;
    if (Check(mid)) {
      ans = mid;
      high = mid - 1;
    } else {
      low = mid + 1;
    }
  }
  cout << ans << '\n';
  return 0;
}

Compilation message (stderr)

sparklers.cpp: In function 'int main()':
sparklers.cpp:49:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   49 |     long long mid = low + high >> 1;
      |                     ~~~~^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...