답안 #1066561

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1066561 2024-08-20T01:46:26 Z vjudge1 Building Bridges (CEOI17_building) C++17
30 / 100
2 ms 604 KB
        ///huynhocute123///
#include<bits/stdc++.h>
using namespace std;
#define S second
#define F first
#define pii pair<int,int>
#define piii pair<int,pair<int,int>>
#define pb push_back
#define pi M_PI
#define FOR(i, a, b) for(int i = a; i <= b; ++i)
#define REP(i, a, b) for(int i = b; i >= a; --i)
#define ALL(v) v.begin(),v.end()
#define inp(name) if(fopen(name, "r")) freopen(name, "r", stdin);
#define out(name) if(fopen(name, "w")) freopen(name, "w", stdout);
//random_device rd;
//mt19937 rng(rd());
//#define int long long
const int maxN = 1e3  + 9 ;
const int  modd = 1e9 + 7;
const int base = 2309;
const int MAX = 1e9+9;
void minimize(int &u, int v){
    if(v < u) u = v;
}
void maximize(int &u, int v){
    if(v > u) u = v;
}
int n, k, t, m, res, a[maxN], b[maxN], f[maxN], dp[maxN];
int l, r;
bool vis[maxN];
vector<int> e[maxN];
void solve(){
    cin >> n;
    FOR(i ,1 , n)cin>> a[i];
    FOR(i , 1 ,n){
        cin >> b[i];
        f[i] = f[i-1] + b[i];
    }
    dp[1]= 0;
    FOR(i ,2 , n){
        dp[i]= MAX;
        FOR(j ,1 ,i-1){
//            cout << j <<  " " << i << " " << (a[i]- a[j])*(a[i]- a[j])<< " "  <<  f[i -1] - f[j]  <<'\n';
            minimize(dp[i], dp[j ] + (a[i]- a[j])*(a[i]- a[j]) + (f[i -1] - f[j])   );
        }
//        cout << dp[i] <<'\n';
    }
    cout << dp[n];


}
signed main(){
//    freopen("name.inp","r",stdin);
//    freopen("name.out","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    inp("task.inp");
    t = 1;
   // cin >> t;
    while( t-- )solve();

}

Compilation message

building.cpp: In function 'int main()':
building.cpp:13:47: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 | #define inp(name) if(fopen(name, "r")) freopen(name, "r", stdin);
      |                                        ~~~~~~~^~~~~~~~~~~~~~~~~~
building.cpp:57:5: note: in expansion of macro 'inp'
   57 |     inp("task.inp");
      |     ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Runtime error 1 ms 604 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -