제출 #93336

#제출 시각아이디문제언어결과실행 시간메모리
933363zpK개의 묶음 (IZhO14_blocks)C++14
0 / 100
20 ms11512 KiB
#include<bits/stdc++.h> using namespace std; const int mn = 100009, mk = 109; int f[mn][mk], n, k; int l[mn], r[mn], a[mn]; vector<int> v[mn]; int dp[mn][mk]; void upd(int i, int j, int d){ i = n + 1 - i; while(i <= n + 1){ f[i][j] = min(f[i][j], d); i += (i & -i); } } int cnt(int i, int j){ i = n + 1 - i; int ans = 1e9; while(i){ ans = min(ans, f[i][j]); i -= (i & -i); } return ans; } main(){ cin >> n >> k; for(int i = 1; i <= n; i++){ cin >> a[i]; } stack<int> S; for(int i = 1; i <= n; i++){ while(S.size() && a[S.top()] < a[i]) S.pop(); if(!S.size()) l[i] = 1; else l[i] = S.top() + 1; S.push(i); } while(S.size()) S.pop(); for(int i = n; i >= 1; i--){ while(S.size() && a[S.top()] < a[i]) S.pop(); if(!S.size()) r[i] = n; else r[i] = S.top() - 1; S.push(i); } for(int i = 1; i <= n; i++){ v[l[i]].push_back(i); } for(int i = 0; i <= n; i++){ for(int j = 0; j <= k; j++){ dp[i][j] = 1e9; f[i+1][j] = 1e9; } } dp[0][0] = 0; upd(0, 0, 0); for(int i = 1; i <= n; i++){ for(int j = 1; j <= k; j++){ int s = cnt(i - 1, j - 1); for(int x : v[i]){ dp[r[x]][j] = min(dp[r[x]][j], a[x] + s); upd(r[x], j, dp[r[x]][j]); } } } if(dp[n][k] == 1e9) cout <<1/0; cout << dp[n][k] << endl; return 0; }

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

blocks.cpp:24:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
blocks.cpp: In function 'int main()':
blocks.cpp:68:33: warning: division by zero [-Wdiv-by-zero]
     if(dp[n][k] == 1e9) cout <<1/0;
                                ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...