This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
ll n, k, t, i, j, a, lo = 1, hi = (1 << 30), s;
cin >> n >> k >> t;
k--;
vector<ll> v(n);
for (i = 0; i < n; i++)
cin >> v[i];
if (!v[n - 1])
{
cout << 0;
return 0;
}
vector<vector<bool> > dp(n);
queue<vector<ll> > q;
for (i = 0; i < n; i++)
dp[i].resize(i + 1);
while (hi - lo > 1)
{
s = (hi + lo) / 2;
for (i = 0; i < n; i++)
{
for (j = 0; j <= i; j++)
dp[i][j] = 0;
}
dp[k][k] = 1;
q.push({k, k});
while (!q.empty())
{
i = q.front()[0];
j = q.front()[1];
q.pop();
a = 2 * t * s * (i - j + 1);
if (j && !dp[i][j - 1] && v[i] - v[j - 1] <= a)
{
dp[i][j - 1] = 1;
q.push({i, j - 1});
}
if (i < n - 1 && !dp[i + 1][j] && v[i + 1] - v[j] <= a)
{
dp[i + 1][j] = 1;
q.push({i + 1, j});
}
}
if (dp[n - 1][0])
hi = s;
else
lo = s;
}
cout << hi;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |