Submission #1117588

#TimeUsernameProblemLanguageResultExecution timeMemory
1117588vjudge1Building Bridges (CEOI17_building)C++17
30 / 100
3063 ms14808 KiB
//#pragma GCC optimize("O3,unroll-loops") //#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define ll long long #define F first #define S second #define ull unsigned long long #define db double #define ldb long double #define pb push_back #define pf push_front #define ppb pop_back #define ppf pop_front #define yes cout << "YES\n" #define no cout << "NO\n" #define ordered_set tree < ll, null_type, less < ll > , rb_tree_tag, tree_order_statistics_node_update > #define all(x) x.begin(), x.end() const int mod = 1e9 + 7; const int N = 500001; using namespace std; using namespace __gnu_pbds; ll n, m, a, b, c, p[N], f[N], dp[N], pr[N]; ll binpow(ll a, ll b) { a %= mod; if (b == 0) { return 1; } else if (b % 2 == 1) { return binpow(a, b - 1) % mod * a % mod; } else { ll t = binpow(a, b / 2) % mod; return t * t % mod; } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++){ cin >> p[i]; } for (int i = 1; i <= n; i++){ cin >> f[i]; pr[i] = f[i] + pr[i - 1]; } for (int i = 2; i <= n; i++){ dp[i] = 1e18; for (int y = i - 1; y >= 1; y--){ dp[i] = min (dp[y] + pr[i - 1] - pr[y] + abs (p[i] - p[y]) * abs (p[i] - p[y]), dp[i]); } // cout << dp[i] << ' '; } cout << dp[n]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...