제출 #939002

#제출 시각아이디문제언어결과실행 시간메모리
939002Darren0724별자리 3 (JOI20_constellation3)C++17
0 / 100
8 ms1880 KiB
#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=1e5; 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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...