제출 #853319

#제출 시각아이디문제언어결과실행 시간메모리
853319manizareBuilding Bridges (CEOI17_building)C++14
30 / 100
3036 ms9860 KiB
#include <bits/stdc++.h> 

#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second 
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define Pii pair< pii , pii >
#define int long long

using namespace std ;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 4e5 + 10 , maxq = 1e7 + 1 ,  inf = 1e8 + 10 , mod= 998244353 ,lg = 20 ;
int dp[maxn] , h[maxn] , w[maxn]; 
signed main(){
  ios::sync_with_stdio(false); cin.tie(0) ;
  int n ;
  cin >> n;
  for(int i =1 ; i<= n ;i++){
    cin >> h[i] ;
  }
  int ans= 0 ; 
  for(int i = 1; i <= n ; i++){
    cin >> w[i] ;
  }
  for(int i = 2; i <= n ; i++){
    int sm =0  ;
    dp[i] = inf ;
    for(int j = i-1 ; j >= 1; j--){
      dp[i] = min(sm + (h[i] - h[j]) * (h[i] - h[j]) + dp[j], dp[i]) ;
      sm += w[j] ; 
    }
  }
  cout << dp[n] ;
}
/*

*/

컴파일 시 표준 에러 (stderr) 메시지

building.cpp: In function 'int main()':
building.cpp:24:7: warning: unused variable 'ans' [-Wunused-variable]
   24 |   int ans= 0 ;
      |       ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...