답안 #703706

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
703706 2023-02-28T07:12:44 Z mychecksedad Building Bridges (CEOI17_building) C++17
0 / 100
3000 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[1]]] + pref[i - 1] - pref[last[h[1]]];
    for(ll j = min(h[i] + 10000, MX*1LL); j >= max(0ll, h[i] - 10000); --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 6 ms 15956 KB Output is correct
2 Correct 8 ms 15956 KB Output is correct
3 Correct 9 ms 15956 KB Output is correct
4 Correct 22 ms 15956 KB Output is correct
5 Incorrect 18 ms 16028 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3079 ms 18324 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 15956 KB Output is correct
2 Correct 8 ms 15956 KB Output is correct
3 Correct 9 ms 15956 KB Output is correct
4 Correct 22 ms 15956 KB Output is correct
5 Incorrect 18 ms 16028 KB Output isn't correct
6 Halted 0 ms 0 KB -