이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define LL long long
using namespace std;
LL n,k;
LL arr[100005];
LL dp[100000+5][105][3];// n k status
bool visited[100005][105][3];
LL f(LL idx,LL kelompok, LL status)
{
// printf("idx =%lld ,kelompok=%lld, status=%lld\n",idx,kelompok,status);
if(idx==n+1 && kelompok==k && status ==0)return 0;
if(kelompok>=k|| idx>n)return 1e18;
if(visited[idx][kelompok][status])return dp[idx][kelompok][status];
visited[idx][kelompok][status];
LL &dyn=dp[idx][kelompok][status];
dyn=1e18;
if(status==0)
{
dyn=min(dyn,f(idx+1,kelompok,1)+arr[idx]);
dyn=min(dyn,f(idx+1,kelompok+1,0)+arr[idx]);
}
else if(status==1)
{
dyn=min(dyn,f(idx+1,kelompok+1,0)+arr[idx]-arr[idx-1]);
// cout<<dyn<<endl;
dyn=min(dyn,f(idx+1,kelompok,status)+arr[idx]-arr[idx-1]);
// cout<<dyn<<endl;
}
// printf("dp[%lld][%lld][%lld]=%lld\n",idx,kelompok,status,dyn);
return dyn;
}
int main()
{
scanf("%lld %lld",&n,&k);
for(LL a=1;a<=n;a++)scanf("%lld",&arr[a]);
sort(arr+1,arr+n+1);
printf("%lld\n",f(1,0,0));
}
컴파일 시 표준 에러 (stderr) 메시지
blocks.cpp: In function 'long long int f(long long int, long long int, long long int)':
blocks.cpp:14:31: warning: statement has no effect [-Wunused-value]
14 | visited[idx][kelompok][status];
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
blocks.cpp: In function 'int main()':
blocks.cpp:34:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | scanf("%lld %lld",&n,&k);
| ~~~~~^~~~~~~~~~~~~~~~~~~
blocks.cpp:35:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
35 | for(LL a=1;a<=n;a++)scanf("%lld",&arr[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... |