Submission #87312

#TimeUsernameProblemLanguageResultExecution timeMemory
873127PolygonzK blocks (IZhO14_blocks)C++11
100 / 100
426 ms43324 KiB
using namespace std ; #include <bits/stdc++.h> /* #7th-Polygon */ typedef pair < int , int > IntInt ; const int N = 1e5 + 7 ; const int K = 100 + 7 ; unsigned int n , k , a[N] , dp[N][K] ; int main() { ios::sync_with_stdio(false) ; cout.tie(nullptr) ; cin.tie(nullptr) ; cin >> n >> k ; for (int i = 1 ; i <= n ; ++i) cin >> a[i] ; memset(dp , -1 , sizeof(dp)) ; dp[0][1] = 0 ; for (int i = 1 ; i <= n ; ++i) dp[i][1] = max(dp[i - 1][1] , a[i]) ; for (int b = 2 ; b <= k ; ++b) { stack < IntInt > my_stack ; for (int i = b ; i <= n ; ++i) { int min_dp = dp[i - 1][b - 1] ; for ( ; my_stack.size() ; my_stack.pop()) { if (a[my_stack.top().first] > a[i]) break ; min_dp = min(min_dp , my_stack.top().second) ; } dp[i][b] = min(min_dp + a[i] , dp[my_stack.size() ? my_stack.top().first : 0][b]) ; my_stack.emplace(i , min_dp) ; } } cout << dp[n][k] << "\n" ; return 0 ; }

Compilation message (stderr)

blocks.cpp: In function 'int main()':
blocks.cpp:17:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 1 ; i <= n ; ++i)
                      ~~^~~~
blocks.cpp:23:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 1 ; i <= n ; ++i)
                      ~~^~~~
blocks.cpp:26:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int b = 2 ; b <= k ; ++b)
                      ~~^~~~
blocks.cpp:29:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = b ; i <= n ; ++i)
                          ~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...