답안 #939003

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
939003 2024-03-06T03:23:46 Z Darren0724 별자리 3 (JOI20_constellation3) C++17
0 / 100
8 ms 1884 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#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=1e18;
int32_t main() {
    LCBorz;
    int n;cin>>n;
    vector<int> h(n+2),g[n+1],no(n+2,INF);
    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);
    }
    no[0]=0;
    dp[0][0]=0;
    for(int i=1;i<=n;i++){
        int total=0;
        for(int j:g[i]){
            total+=v[i][j];
        }
        for(int j=1;j<=h[i];j++){
            
            dp[i][j]=min(dp[i][j],no[i-1]+total-v[i][j]);
            if(!v[i][j])dp[i][j]=min(dp[i][j],dp[i-1][j]+total-v[i][j]);
            if(j<=h[i]){
                for(int k=1;k<=h[i-1];k++){
                    if(k>h[i]){
                        dp[i][j]=min(dp[i][j],dp[i-1][k]+total-v[i][j]);
                    }
                    else if(j>h[i-1]){
                        dp[i][k]=min(dp[i][k],dp[i-1][k]+total-v[i][j]);
                    }
                }
            }
            
        }
        no[i]=*min_element(dp[i].begin()+h[i+1]+1,dp[i].end());
        no[i]=min(no[i],no[i-1]+total);
    }
    cout<<min(*min_element(all(dp[n])),no[n])<<endl;
    
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 1884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 1884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 1884 KB Output isn't correct
2 Halted 0 ms 0 KB -