이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
int range_len[2000005];
pair<int,int> memo[4005][4005];
int N,D,T;
pair<int,int> operator+ (pair<int,int> a, pair<int,int> b){
return {a.first+b.first,a.second+b.second};
}
pair<int,int> solve(int K){
for (int x = 0; x<=N; x++){
memo[N][x] = {0,0};
}
int v1 = 0;
set<int> inc_loc;
multiset<int> inc_loc_2;
int v2 = 0;
int offset = 0;
if (range_len[N-1]>0){
v1 = 1;
}
else{
inc_loc.insert(1);
}
for (int x = N-2; x>=0; x--){
offset++;v1++;
if (range_len[x]==0){
v1--;
inc_loc.insert(1-offset);
}
else{
while ((!inc_loc.empty())&&(*inc_loc.begin())+offset<=range_len[x]+1){
inc_loc.erase(inc_loc.begin());
v1++;
}
while ((!inc_loc_2.empty())&&(*inc_loc_2.begin())+offset<=range_len[x]+1){
inc_loc_2.erase(inc_loc_2.begin());
v2++;
}
}
int other_val = v1+K;
int last_erased = 999999999;
while (v1+inc_loc.size()>other_val){
last_erased = (*--inc_loc.end());
inc_loc.erase(--inc_loc.end());
}
if (last_erased!=999999999) inc_loc_2.insert(last_erased);
}
/*
for (int x = N-1; x>=0; x--){
for (int o = 0; o<=N; o++){
memo[x][o] = memo[x+1][0]+make_pair(K+(range_len[x]>0),1);
if (o>range_len[x]) memo[x][o] = min(memo[x][o],memo[x+1][o-1]+make_pair(1,0));
else memo[x][o] = min(memo[x][o],memo[x+1][max(0LL,range_len[x]-1)]+make_pair((range_len[x]>0),0));
printf("ans %lld %lld = %lld,%lld\n",x,o,memo[x][o]);
}
}
*/
return {v1,v2};
}
main(){
scanf("%lld%lld%lld",&N,&D,&T);
for (int x = 0; x<N; x++){
int a;
scanf("%lld",&a);
range_len[x] = T-a+1;
if (range_len[x]<0) range_len[x] = 0;
if (x+range_len[x]>N) range_len[x] = N-x;
}
int a = -1;
int b = N;
while (a+1<b){
//printf("try %lld\n",(a+b)/2);
if (solve((a+b)/2).second>D){
a = (a+b)/2;
}
else b = (a+b)/2;
}
pair<int,int> res = solve(b);
//printf("b = %lld, res = %lld %lld\n",b,res);
printf("%lld",res.first-res.second*b-b*(D-res.second));
}
컴파일 시 표준 에러 (stderr) 메시지
prison.cpp: In function 'std::pair<long long int, long long int> solve(long long int)':
prison.cpp:46:33: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long long int' [-Wsign-compare]
46 | while (v1+inc_loc.size()>other_val){
| ~~~~~~~~~~~~~~~~~^~~~~~~~~~
prison.cpp: At global scope:
prison.cpp:66:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
66 | main(){
| ^~~~
prison.cpp: In function 'int main()':
prison.cpp:67:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
67 | scanf("%lld%lld%lld",&N,&D,&T);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
prison.cpp:70:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
70 | scanf("%lld",&a);
| ~~~~~^~~~~~~~~~~
# | 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... |