답안 #703708

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
703708 2023-02-28T07:17:14 Z mychecksedad Building Bridges (CEOI17_building) C++17
0 / 100
2475 ms 18324 KB
/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define all(x) x.begin(), x.end()
const int N = 1e6+100, MX = 1e6, K = 20;

int n;
ll dp[N], h[N], w[N], pref[N], last[N];
void solve(){
  cin >> n;
  for(int i = 1; i <= n; ++i) cin >> h[i];
  for(int i = 1; i <= n; ++i) cin >> w[i];
  for(int i = 0; i <= MX; ++i) dp[i] = 1e18, last[i] = -1;

  pref[0] = 0;
  for(int i = 1; i <= n; ++i) pref[i] = pref[i - 1] + w[i];

  dp[h[1]] = 0;
  last[h[1]] = 1;
  for(int i = 2; i <= n; ++i){
    if(last[h[i]] != -1)
      dp[h[i]] = dp[h[i]] + pref[i - 1] - pref[last[h[i]]];
    else
      dp[h[i]] = dp[last[h[i - 1]]] + (h[i-1]-h[i])*(h[i-1]-h[i]);
    for(ll j = min(h[i] + 5000, MX*1LL); j >= max(0ll, h[i] - 5000); --j){
      if(last[j] != -1)
        dp[h[i]] = min(dp[j] + (h[i] - j) * (h[i] - j) + pref[i - 1] - pref[last[j]], dp[h[i]]);
    }
    last[h[i]] = i;
  }
  cout << dp[h[n]];
}


int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int T = 1, aa;
  // cin >> T;aa=T;
  while(T--){
    // cout << "Case #" << aa-T << ": ";
    solve();
    cout << '\n';
  }
  return 0;
 
}

Compilation message

building.cpp: In function 'int main()':
building.cpp:42:14: warning: unused variable 'aa' [-Wunused-variable]
   42 |   int T = 1, aa;
      |              ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 15956 KB Output is correct
2 Correct 8 ms 15956 KB Output is correct
3 Incorrect 7 ms 15916 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2475 ms 18324 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 15956 KB Output is correct
2 Correct 8 ms 15956 KB Output is correct
3 Incorrect 7 ms 15916 KB Output isn't correct
4 Halted 0 ms 0 KB -