이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define N 2013
using namespace std;
int dp[N][N];
int W1[N], W2[N];
int n, p, q;
vector<int> a;
bool ok(int w){
for(int i = 0; i <= n; i++) for(int j = 0; j <= n; j++) dp[i][j] = (1 << 30); dp[0][0] = 0;
int w1 = 0, w2 = 0;
for(int i = 1; i <= n; i++){
while(w2 < n && a[w2] <= a[i - 1] - w * 2) w2++;
while(w1 < n && a[w1] <= a[i - 1] - w) w1++;
W1[i] = w1, W2[i] = w2;
}
for(int j = 0; j <= q; j++){
for(int i = 1; i <= n; i++){
if(j > 0) dp[j][i] = min(dp[j][i], dp[j - 1][W2[i]]);
dp[j][i] = min(dp[j][i], dp[j][W1[i]] + 1);
}
for(int i = 1; i <= n; i++) dp[j + 1][i] = min(dp[j][i], dp[j + 1][i]);
}
return dp[q][n] <= p;
}
int main(){
cin >> n >> p >> q;
p += q - min(n / 2, q);
p = min(n, p); q = min(n / 2, q);
for(int i = 0; i < n; i++){
int v; cin >> v;
a.push_back(v);
}
sort(a.begin(), a.end());
int l, r;
for(l = 0, r = 1e9 + 1; l != r;){
int m = (l + r) / 2;
if(ok(m)){
r = m;
}else{
l = m + 1;
}
}
cout << l << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
watching.cpp: In function 'bool ok(int)':
watching.cpp:11:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
11 | for(int i = 0; i <= n; i++) for(int j = 0; j <= n; j++) dp[i][j] = (1 << 30); dp[0][0] = 0;
| ^~~
watching.cpp:11:80: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
11 | for(int i = 0; i <= n; i++) for(int j = 0; j <= n; j++) dp[i][j] = (1 << 30); dp[0][0] = 0;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |