제출 #1342650

#제출 시각아이디문제언어결과실행 시간메모리
1342650dex111222333444555Building Bridges (CEOI17_building)C++20
30 / 100
3093 ms1812 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) 메시지

building.cpp: In function 'int main()':
building.cpp:59:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
building.cpp:60:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...