답안 #938962

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
938962 2024-03-06T01:47:06 Z Darren0724 별자리 3 (JOI20_constellation3) C++17
0 / 100
1 ms 1112 KB
#include <bits/stdc++.h>
using namespace std;
#define LCBorz ios_base::sync_with_stdio(false); cin.tie(0);
#define all(x) x.begin(), x.end()
#define endl '\n'
const int N=200005;
const int INF=1e9;
int32_t main() {
    LCBorz;
    int n;cin>>n;
    vector<int> h(n+2),g[n+1];
    vector<vector<int>> v(n+1,vector<int>(n+2)),dp(n+1,vector<int>(n+2,INF));
    for(int i=1;i<=n;i++){
        cin>>h[i];h[i]=n-h[i];
    }
    int m;cin>>m;
    for(int i=1;i<=m;i++){
        int a,b,c;cin>>a>>b>>c;
        b=n-b+1;
        v[a][b]=c;
        g[a].push_back(b);
    }
    dp[0][0]=0;
    for(int i=1;i<=n;i++){
        if(h[i]==0){
            for(int j=0;j<=n;j++){
                dp[i][0]=min(dp[i][0],dp[i-1][j]);
            }
            continue;
        }
        int total=0;
        for(int j:g[i]){
            total+=v[i][j];
        }
        int mx=0;
        for(int j=n;j>=1;j--){
            if(j>h[i-1])mx=max(mx,v[i][j]);
            dp[i][j]=min(dp[i][j],dp[i-1][j]+total-mx);
        }
        int mn=INF;
        for(int j=n;j>=1;j--){
            dp[i][j]=min(dp[i][j],mn+total-v[i][j]);
            dp[i][j]=min(dp[i][j],dp[i-1][j]+total);
            dp[i][j]=min(dp[i][j],dp[i-1][0]+total-v[i][j]);
            mn=min(mn,dp[i-1][j]);
        }
    }
    cout<<*min_element(all(dp[n]))<<endl;
    
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1112 KB Output isn't correct
2 Halted 0 ms 0 KB -