| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1342650 | dex111222333444555 | Building Bridges (CEOI17_building) | C++20 | 3093 ms | 1812 KiB |
#include <bits/stdc++.h>
#define all(v) begin(v), end(v)
#define ii pair<int, int>
#define fi first
#define se second
#define siz(v) (int)(v).size()
#define lli pair<long long, int>
#define BIT(x, i) (((x) >> (i)) & 1)
#define MASK(i) (1LL << (i))
using namespace std;
const int MAXN = 1e5 + 6, infINT = 1e9 + 1321, mod = 1e9 + 7, base = 1e9 + 1;
const long long inf = 1e18 + 1231;
template<class X, class Y> bool minimize(X &x, const Y &y){return x > y ? x = y, 1: 0;}
void add(int &a, const int &b){
a += b;
if (a >= mod) a -= mod;
}
void sub(int &a, const int &b){
a -= b;
if (a < 0) a += mod;
}
int mul(const int &a, const int &b){
return 1LL * a * 1LL * b % mod;
}
int numVal, height[MAXN], cost[MAXN];
long long f[MAXN];
void input(){
cin >> numVal;
for(int i = 1; i <= numVal; i++) cin >> height[i];
for(int i = 1; i <= numVal; i++) cin >> cost[i];
}
void solve(){
memset(f, 0x3f, sizeof f);
f[1] = 0;
for(int i = 2; i <= numVal; i++){
long long sumCost = 0;
minimize(f[i], f[i - 1] + 1LL * (height[i] - height[i - 1]) * 1LL * (height[i] - height[i - 1]));
for(int j = i - 1; j >= 1; j--){
sumCost += cost[j];
minimize(f[i], f[j - 1] + sumCost + 1LL * (height[i] - height[j - 1]) * 1LL * (height[i] - height[j - 1]));
}
}
cout << f[numVal] << '\n';
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define task "test"
if (fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
input();
solve();
cerr << (1.0 * clock()) / CLOCKS_PER_SEC << ".s\n";
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
