| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 31908 | chonka | K개의 묶음 (IZhO14_blocks) | C++98 | 143 ms | 87964 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<stdio.h>
#include<stack>
using namespace std ;
#define MAXN 100007
#define MAXK 107
int n , k ;
long long a[ MAXN ] ;
long long dp[ MAXN ][ MAXK ] ;
long long val[ MAXN ] ;
long long pref[ MAXN ] ;
long long inf = 0 ;
void input ( ) {
scanf ( "%d%d" , &n , &k ) ;
int i ;
inf = 1 ;
for ( i = 1 ; i <= 15 ; i ++ ) {
inf *= 10 ;
}
for ( i = 1 ; i <= n ; i ++ ) {
scanf ( "%lld" , &a[ i ] ) ;
}
a[ 0 ] = pref[ 0 ] = inf ;
}
void solve ( ) {
int i , j ;
stack < int > s ;
for ( i = 1 ; i <= k ; i ++ ) {
while ( s.empty ( ) == false ) { s.pop ( ) ; }
s.push ( i - 1 ) ;
a[ i - 1 ] = inf ;
for ( j = i ; j <= n ; j ++ ) {
while ( s.empty ( ) == false && a[ s.top ( ) ] <= a[ j ] ) {
s.pop ( ) ;
}
val[ s.size ( ) ] = dp[ s.top ( ) ][ i - 1 ] + a[ j ] ;
pref[ s.size ( ) ] = min ( pref[ s.size ( ) - 1 ] , val[ s.size ( ) ] ) ;
dp[ j ][ i ] = pref[ s.size ( ) ] ;
s.push ( j ) ;
}
}
printf ( "%lld\n" , dp[ n ][ k ] ) ;
}
int main ( ) {
input ( ) ;
solve ( ) ;
return 0 ;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | 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... | ||||
