답안 #161886

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
161886 2019-11-05T07:06:23 Z shayan_p Building Bridges (CEOI17_building) C++14
30 / 100
3000 ms 2804 KB
// Remember...

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int maxn=1e5+10,mod=1e9+7;
const ll inf=1e18;

ll dp[maxn];
int a[maxn], b[maxn];

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie();

    int n; cin>>n;
    for(int i=0;i<n;i++){
	cin>>a[i];
    }
    for(int i=0;i<n;i++){
	cin>>b[i];
    }
    for(int i=1;i<n;i++){
	ll num=0;
	dp[i]= inf;
	for(int j=i-1;j>=0;j--){
	    dp[i]= min(dp[i], dp[j] + num + 1ll*(a[i]-a[j])*(a[i]-a[j])); 
	    num+= b[j];
	}
    }
    return cout<<dp[n-1]<<endl,0;
}
// Deathly mistakes:
//  * Read the problem carefully.
//  * Check maxn.
//  * Overflows.


// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3039 ms 2804 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Execution timed out 3039 ms 2804 KB Time limit exceeded
7 Halted 0 ms 0 KB -