Submission #874341

# Submission time Handle Problem Language Result Execution time Memory
874341 2023-11-16T17:13:20 Z NHANGIOI Building Bridges (CEOI17_building) C++17
30 / 100
3000 ms 2908 KB
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define all(a)  a.begin(),a.end()

#define MASK(i) (1LL << (i))
#define count_bit(a) __builtin_popcountll(a) // đếm số bit đang bật
#define BIT(x, i) ((x) & MASK(i)) // trạng thái của bit thứ i trong x
#define SET_ON(x, i) ((x) | MASK(i)) // bật bit thứ i trong x
#define SET_OFF(x, i) ((x) & ~MASK(i)) // tắt bit thứ i trong x

#define FOR(i,a,b)	for(int i=(a);i<=(b);++i)
#define FORD(i,a,b)	for(int i=(a);i>=(b);--i)
#define endl '\n'
using ll = long long;
using ull = unsigned long long;
using ld=long double;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l,ll r){ return l+rng()%(r-l+1);}
const int BASE=257;
const ll oo=1e18;
const int INF=1e9+7;
const ll MOD=1e9+7;
const int NMAX=1e5+1;
/*
    ,_
    (OvO)
    /)_")
    /_/
*/
signed main()
{
	fastio;
    #define TASK "a"
    if(fopen(TASK".INP", "r")){
        freopen(TASK".INP", "r", stdin);
        freopen(TASK".OUT", "w", stdout);
    }int n; cin>>n;
    int h[n+1],p[n+1];  
    FOR(i,1,n)  cin>>h[i];
    FOR(i,1,n)  cin>>p[i];
    int pre[n+1];   pre[0]=0;
    FOR(i,1,n)  pre[i]=pre[i-1]+p[i];
    int dp[n+1];
    FOR(i,1,n)  dp[i]=INF;
    dp[1]=0;
    FOR(i,2,n){
        FORD(j,i-1,1){
            int ans=dp[j]+((h[i]-h[j])*(h[i]-h[j]))+pre[i-1]-pre[j];
            dp[i]=min(dp[i],ans);
        }
    }//FOR(i,1,n) cout<<dp[i]<<" ";
    cout<<dp[n];
    cerr <<endl<< (1.0 * clock() / CLOCKS_PER_SEC) << endl;
    return 0;
}

Compilation message

building.cpp: In function 'int main()':
building.cpp:40:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
building.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         freopen(TASK".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3033 ms 2908 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Execution timed out 3033 ms 2908 KB Time limit exceeded
7 Halted 0 ms 0 KB -