Submission #703705

#TimeUsernameProblemLanguageResultExecution timeMemory
703705mychecksedadBuilding Bridges (CEOI17_building)C++17
0 / 100
3051 ms18276 KiB
/* 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[h[1]] + pref[i - 1] - pref[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 (stderr)

building.cpp: In function 'int main()':
building.cpp:42:14: warning: unused variable 'aa' [-Wunused-variable]
   42 |   int T = 1, aa;
      |              ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...