Submission #868262

# Submission time Handle Problem Language Result Execution time Memory
868262 2023-10-31T01:57:06 Z Truly_ Building Bridges (CEOI17_building) C++14
30 / 100
12 ms 3676 KB
#define nametask "bridgepol"
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define SZ(a) (int) a.size()
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FOD(i, b, a) for (int i = b; i >= a; i--)

using namespace std;
typedef long long ll;
typedef pair <int, int> pi;
const int N = 1e5 + 5;
const ll oo = 1e18 + 7;

int n;
int h[N], w[N];
ll s[N], f[N];

ll calc(int i, int j){
    return (s[j] - s[i - 1]);
}

ll calch(int h1, int h2){
    return (1LL * h1 * h1 - 2LL * h1 * h2 + 1LL * h2 * h2);
}

void sub1(){
    f[1] = 0;
    FOR(i, 2, n){
        FOR(j, 1, i - 1) {
            f[i] = min(f[i], f[j] + calch(h[i], h[j]) + calc(j + 1, i - 1));
        }
    }
    cout << f[n];
}

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    if (fopen(nametask".inp", "r")){
        freopen(nametask".inp", "r", stdin);
        freopen(nametask".out", "w", stdout);
    }
    cin >> n;
    FOR(i, 1, n) cin >> h[i];
    FOR(i, 1, n) cin >> w[i];
    FOR(i, 1, n) s[i] = s[i - 1] + w[i];
    FOR(i, 1, n) f[i] = oo;
    if (n <= 1000) sub1();
    //else sub2();
    return 0;
}

Compilation message

building.cpp: In function 'int main()':
building.cpp:43:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |         freopen(nametask".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
building.cpp:44:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |         freopen(nametask".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 2 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 3676 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 2 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Incorrect 12 ms 3676 KB Output isn't correct
7 Halted 0 ms 0 KB -