답안 #1049292

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1049292 2024-08-08T16:00:28 Z Ahmed57 전선 연결 (IOI17_wiring) C++17
0 / 100
1 ms 348 KB
#include "bits/stdc++.h"
using namespace std;
long long min_total_length(vector<int> r, vector<int> b){
    vector<pair<long long,int>> v;
    for(auto i:r){
        v.push_back({i,0});
    }
    for(auto i:b){
        v.push_back({i,1});
    }
    sort(v.begin(),v.end());
    int n = v.size();
    long long pref[n+1] = {0};
    for(int i = 0;i<n;i++){
        pref[i+1] = v[i].first;
        pref[i+1]+=pref[i];
    }
    int st[n],en[n];
    for(int i = 0;i<n;i++){
        if(i==0||v[i].first!=v[i-1].first){
            st[i] = i;
        }else st[i] = st[i-1];
    }
    for(int i = n-1;i>=0;i--){
        if(i==n-1||v[i].first!=v[i+1].first){
            en[i] = i;
        }else en[i] = en[i+1];
    }
    long long dp[n+1][2];
    for(int i = 0;i<=n;i++)dp[i][0] = dp[i][1] = 1e18;
    dp[0][0] = 0;
    for(int i = 1;i<=n;i++){
        int S = st[i-1];
        int E = en[i-1];
        if(S==i-1)dp[i][0] = min(dp[i][0],dp[i-1][1]);
        int V = i-S;
        if(S!=0)dp[i][0] = min(dp[i][0],dp[i-1][0]+abs(v[i-1].first-v[S-1].first));
        if(S-V>=0)dp[i][0] = min(dp[i][0],dp[i-1][0]+pref[i]-pref[S]-(pref[S]-pref[S-V]));
        if(E<n-1)dp[i][1] = min(dp[i][1],dp[i-1][0]+abs(v[i-1].first-v[E+1].first));
        dp[i][0] = min(dp[i][0],dp[i][1]);
    }
    return dp[n][0];
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '25859', found: '443'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '904', found: '42'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '316', found: '42'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB 3rd lines differ - on the 1st token, expected: '27', found: '10'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '25859', found: '443'
2 Halted 0 ms 0 KB -