이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
* author: _minhduc
* created: 14-12-2023 13:30:37
**/
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define taskname ""
using namespace std;
const int maxN = (int)(2e6);
int n,d,a;
int arr[maxN+5];
namespace sub1 {
const int N = (int)(500);
int dp[N+5][N+5];
void main() {
for (int i = 0; i < n; i++)
cin >> arr[i];
for (int i = 0; i <= n; i++)
for (int j = 0; j <= d+1; j++)
dp[i][j] = (int)(1e16);
dp[n][0] = 0;
for (int i = n-1; i >= 0; i--)
for (int j = 1; j <= d+1; j++) {
int cnt = 0, mn = arr[i];
for (int k = i+1; k <= n; k++) {
cnt += (mn <= a);
dp[i][j] = min(dp[i][j],dp[k][j-1] + cnt);
mn = min(mn+1,arr[k]);
}
}
cout << dp[0][d+1];
}
}
namespace sub6 {
int F[maxN+5],dd[maxN+5];
void main() {
int mx = 0;
priority_queue<pii,vector<pii>,greater<pii>> pq;
for (int i = 1; i <= n; i++)
cin >> arr[i];
for (int i = 1; i <= n; i++)
F[i] = F[i-1] + (arr[i] > a);
for (int i = 1; i <= n; i++)
if (arr[i] < a)
mx = max(mx,a-arr[i]+i);
else {
if (mx >= i)
if (pq.size() < d)
pq.push({F[mx] - F[i-1],i});
else {
pq.push({F[mx] - F[i-1],i});
pq.pop();
}
mx = 0;
}
while (pq.size()) {
dd[pq.top().second] = 1;
pq.pop();
}
int res = n;
for (int i = 1; i <= n; i++)
if (arr[i] < a)
mx = max(mx,a-arr[i]+i);
else {
if (dd[i]) {
res--;
mx = 0;
} else {
if (mx < i) {
res--;
mx = 0;
}
}
}
cout << res;
}
}
int32_t main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef LOCAL
freopen(".inp", "r", stdin);
freopen(".out", "w", stdout);
#endif
#ifdef ONLINE_JUDGE
// freopen(taskname".inp", "r", stdin);
// freopen(taskname".out", "w", stdout);
#endif
cin >> n >> d >> a;
if (n <= 500)
sub1::main();
else
sub6::main();
}
컴파일 시 표준 에러 (stderr) 메시지
prison.cpp: In function 'void sub6::main()':
prison.cpp:57:35: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<long long int, long long int>, std::vector<std::pair<long long int, long long int> >, std::greater<std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
57 | if (pq.size() < d)
| ~~~~~~~~~~^~~
prison.cpp:56:20: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
56 | if (mx >= i)
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |