이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)1003;
const int infint = (int)2e9;
const ll inf = (ll)2e18;
ll dp[MAXN][MAXN], part[MAXN], a[MAXN], dist[MAXN], n, k, T;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> k >> T;
for (int i = 1; i <= n; i++)
cin >> a[i];
T *= 2;
for (int i = 1; i <= n; i++)
dist[i] = abs(a[i] - a[k]);
part[1] = dist[1];
for (int i = 2; i <= n; i++)
part[i] = part[i - 1] + dist[i];
for (int i = 1; i <= n; i++)
dp[i][i] = -1;
dp[k][k] = 0;
for (int len = 1; len < n; len++)
for (int i = 1; i <= n - len; i++)
{
int j = i + len;
if(dp[i + 1][j] == -1 && dp[i][j - 1] == -1)
dp[i][j] = -1;
else
if(dp[i + 1][j] == -1)
dp[i][j] = dp[i][j - 1];
else
if(dp[i][j - 1] == -1)
dp[i][j] = dp[i + 1][j];
else
dp[i][j] = min(dp[i + 1][j], dp[i][j - 1]);
if(dp[i][j] != -1)
dp[i][j] = max(dp[i][j], (part[j] - part[i - 1] + (j - i) * T - 1) / ((j - i) * T));
}
cout << dp[1][n];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |