Submission #481257

# Submission time Handle Problem Language Result Execution time Memory
481257 2021-10-20T06:22:10 Z FatihSolak Skyline (IZhO11_skyline) C++17
100 / 100
229 ms 1180 KB
#include <bits/stdc++.h>
#define N 305
using namespace std;
int h[N];
void solve(){
    int n;
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> h[i];
    }
    vector<vector<int>> dp(N,vector<int>(N,1e9));
    dp[0][0] = 0;
    for(int x=1;x<=n;x++){
        vector<vector<int>> ndp(N,vector<int>(N,1e9));
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                ndp[max(0,j- i)][max(0,h[x] - i)] = min(ndp[max(0,j- i)][max(0,h[x] - i)],dp[i][j] + 7*i);
            }
        }
        for(int i=N-1;i>=0;i--){
            for(int j=N-1;j>=0;j--){
                ndp[i][max(0,j-1)] = min(ndp[i][max(0,j-1)],ndp[i][j] + 3);
                ndp[max(0,i-1)][max(0,j-1)] = min(ndp[max(0,i-1)][max(0,j-1)],ndp[i][j] + 5);
            }
        }
        dp = ndp;
    }
    cout << dp[0][0];
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    #ifdef Local
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    #ifdef Local
    cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 972 KB Output is correct
2 Correct 3 ms 984 KB Output is correct
3 Correct 6 ms 1016 KB Output is correct
4 Correct 54 ms 1168 KB Output is correct
5 Correct 6 ms 1060 KB Output is correct
6 Correct 9 ms 1056 KB Output is correct
7 Correct 8 ms 1044 KB Output is correct
8 Correct 6 ms 1044 KB Output is correct
9 Correct 10 ms 1056 KB Output is correct
10 Correct 22 ms 1180 KB Output is correct
11 Correct 110 ms 1064 KB Output is correct
12 Correct 27 ms 1056 KB Output is correct
13 Correct 128 ms 1064 KB Output is correct
14 Correct 165 ms 1060 KB Output is correct
15 Correct 212 ms 1108 KB Output is correct
16 Correct 189 ms 1056 KB Output is correct
17 Correct 229 ms 1056 KB Output is correct
18 Correct 226 ms 1052 KB Output is correct
19 Correct 226 ms 1096 KB Output is correct
20 Correct 221 ms 1056 KB Output is correct