제출 #1204521

#제출 시각아이디문제언어결과실행 시간메모리
1204521Bui_Quoc_CuongStove (JOI18_stove)C++20
0 / 100
150 ms327680 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int n, k; int a[maxn]; namespace sub1 { long long dp[5005][5005]; long long opt[5005][5005]; void solve() { memset(dp,0x3f,sizeof dp); memset(opt,0x3f,sizeof opt); // for(int i=1;i<=n;i++)for(int j=1;j<=k;j++) // { // for(int v=1;v<=i;v++) dp[i][j]=min(dp[i][j],dp[v-1][j-1] + a[i]+1-a[v]); // } // cout << dp[n][k]; dp[0][0] = opt[0][0]=0; for(int j=1;j<=k;j++) { for(int i=1;i<=n;i++) { opt[i][j-1] = min(opt[i-1][j-1], dp[i-1][j-1] - a[i]); } for(int i=1;i<=n;i++) { dp[i][j] = opt[i][j-1] + a[i]+1; } } cout << dp[n][k]; } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); freopen("joi18_stove.inp", "r", stdin); freopen("joi18_stove.out", "w", stdout); cin >> n >> k; for(int i=1;i<=n;i++) cin>>a[i]; sort(a+1,a+1+n); return sub1::solve(),0; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

stove.cpp: In function 'int main()':
stove.cpp:39:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |     freopen("joi18_stove.inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:40:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |     freopen("joi18_stove.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...