제출 #635309

#제출 시각아이디문제언어결과실행 시간메모리
635309ThMinh_K개의 묶음 (IZhO14_blocks)C++14
0 / 100
1 ms340 KiB
#include<bits/stdc++.h> #define forin(i,a,b) for(int i=a;i<=b;++i) #define ll long long using namespace std; const int N = 1e5 + 10, M = 1e2 + 10; int n, k; ll a[N], dp[N][M], sp[N][17]; void build() { forin(i,1,n) sp[i][0] = a[i]; forin(j,1,log2(n)) forin(i,1,n - (1<<j) + 1) { sp[i][j] = max(sp[i][j - 1], sp[i + (1<<(j - 1))][j - 1]); } } ll cost(int f, int l) { if(f > l) return 1e16; int j = (int)log2(l - f + 1); return max(sp[f][j], sp[l - (1<<j) + 1][j]); } void solve(int f, int l, int from, int to, int k) { if(f > l) return; int mid = f + l >>1, p; ll &a = dp[mid][k]; a = 1e16; forin(i,from,to) { ll nw = dp[i - 1][k - 1] + cost(i, mid); if(a > nw) { a = nw; p = i; } } solve(f, mid - 1, from, p, k); solve(mid + 1, l, p, to, k); } int main () { cin.tie(0)->sync_with_stdio(0); if(fopen("Task.inp","r")) { freopen("Task.inp","r",stdin); freopen("WA.out","w",stdout); } cin>>n>>k; forin(i,1,n) cin>>a[i]; build(); dp[0][0] = 0; forin(i,1,n) dp[i][0] = 1e16; forin(i,1,k) { if(i - 1) dp[0][i - 1] = 1e16; solve(1, n, 1, n, i); } cout<<dp[n][k]; }

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

blocks.cpp: In function 'void solve(int, int, int, int, int)':
blocks.cpp:21:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   21 |     int mid = f + l >>1, p;
      |               ~~^~~
blocks.cpp: In function 'int main()':
blocks.cpp:36:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |         freopen("Task.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:37:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         freopen("WA.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
blocks.cpp: In function 'void solve(int, int, int, int, int)':
blocks.cpp:30:10: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
   30 |     solve(f, mid - 1, from, p, k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...