# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
100381 | 2019-03-10T19:23:04 Z | shafinalam | Building Bridges (CEOI17_building) | C++14 | 3000 ms | 8320 KB |
#include <bits/stdc++.h> using namespace std; const int mx = 1e5+5; typedef long long ll; typedef unsigned int ui; typedef unsigned long long ull; typedef pair<int,int>pii; typedef pair<int,pii>piii; #define sf scanf #define pf printf #define input freopen("input.txt","r",stdin) #define output freopen("output.txt","w",stdout) #define inf 1e16 #define ff first #define ss second #define MP make_pair #define pb push_back #define all(v) v.begin(), v.end() #define printcase(cases) printf("Case %d:", cases); #define Unique(a) a.erase(unique(a.begin(),a.end()),a.end()) #define FAST ios_base::sync_with_stdio(0);cout.tie(0) #define endl printf("\n") #define __lcm(a, b) ((a*b)/__gcd(a, b)) int Set(int N,int pos) { return N=N | (1<<pos); } int reset(int N,int pos) { return N= N & ~(1<<pos); } bool check(int N,int pos) { return (bool)(N & (1<<pos)); } ll dp[mx]; ll arr[mx]; ll cost[mx]; int n; ll solve(int pos) { if(pos>=n-1) return 0; if(dp[pos]!=-1) return dp[pos]; ll ret = inf, x = 0; for(int i = pos+1; i < n; i++) { ll tmp = (arr[pos]-arr[i])*(arr[pos]-arr[i]); ret = min(ret, solve(i)+x+tmp); x+=cost[i]; } return dp[pos] = ret; } int main() { sf("%d", &n); for(int i = 0; i < n; i++) sf("%lld", &arr[i]); for(int i = 0; i < n; i++) sf("%lld", &cost[i]); memset(dp, -1, sizeof dp); ll ans = solve(0); pf("%lld\n", ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1124 KB | Output is correct |
2 | Correct | 3 ms | 1152 KB | Output is correct |
3 | Correct | 3 ms | 1152 KB | Output is correct |
4 | Correct | 5 ms | 1152 KB | Output is correct |
5 | Correct | 5 ms | 1152 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3089 ms | 8320 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1124 KB | Output is correct |
2 | Correct | 3 ms | 1152 KB | Output is correct |
3 | Correct | 3 ms | 1152 KB | Output is correct |
4 | Correct | 5 ms | 1152 KB | Output is correct |
5 | Correct | 5 ms | 1152 KB | Output is correct |
6 | Execution timed out | 3089 ms | 8320 KB | Time limit exceeded |
7 | Halted | 0 ms | 0 KB | - |