# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
172673 | 2020-01-02T10:40:10 Z | Swan | K개의 묶음 (IZhO14_blocks) | C++14 | 48 ms | 41660 KB |
#include <bits/stdc++.h> using namespace std; int dp[105][100005]; int a[100005]; int n,k; int main(){ scanf("%d %d",&n,&k); int maxv = 0; memset(dp,0x3f,sizeof(dp)); for (int i=1; i<=n; i++) { scanf("%d",&a[i]); maxv = max(maxv,a[i]); dp[1][i] = maxv; } for (int i=2; i<=k; i++) { stack<int> s1,s2; for (int j=1; j<=n; j++) { int my_dp = dp[i-1][j-1]; while (!s1.empty() && a[s1.top()] < a[j]) { //if(k==2 && j == 1)cout << my_dp << ' ' << s1.top() << endl; my_dp = min(my_dp,s2.top()); s1.pop(); s2.pop(); } if(s1.size() && j>=i)dp[i][j] = dp[i][s1.top()]; s1.push(j); s2.push(min(dp[i-1][j],my_dp)); if(j >= i) { dp[i][j] = min(dp[i][j],a[s1.top()] + s2.top()); } } } cout << dp[k][n]; } /* 10 3 1 5 5 9 10 14 15 16 8 3 */
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 37 ms | 41464 KB | Output is correct |
2 | Correct | 37 ms | 41444 KB | Output is correct |
3 | Correct | 37 ms | 41464 KB | Output is correct |
4 | Correct | 37 ms | 41440 KB | Output is correct |
5 | Correct | 37 ms | 41436 KB | Output is correct |
6 | Correct | 37 ms | 41464 KB | Output is correct |
7 | Correct | 37 ms | 41436 KB | Output is correct |
8 | Correct | 37 ms | 41464 KB | Output is correct |
9 | Correct | 38 ms | 41440 KB | Output is correct |
10 | Incorrect | 38 ms | 41464 KB | Output isn't correct |
11 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 41 ms | 41452 KB | Output is correct |
2 | Correct | 46 ms | 41428 KB | Output is correct |
3 | Correct | 37 ms | 41464 KB | Output is correct |
4 | Correct | 37 ms | 41432 KB | Output is correct |
5 | Correct | 37 ms | 41404 KB | Output is correct |
6 | Correct | 37 ms | 41464 KB | Output is correct |
7 | Correct | 37 ms | 41464 KB | Output is correct |
8 | Correct | 33 ms | 41464 KB | Output is correct |
9 | Correct | 43 ms | 41464 KB | Output is correct |
10 | Incorrect | 38 ms | 41484 KB | Output isn't correct |
11 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 41 ms | 41424 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 48 ms | 41660 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |