Submission #883867

# Submission time Handle Problem Language Result Execution time Memory
883867 2023-12-06T09:44:03 Z JakobZorz Wiring (IOI17_wiring) C++14
0 / 100
1 ms 348 KB
#include"wiring.h"
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;

ll min_total_length(vector<int>r,vector<int>b){
    vector<pair<int,int>>arr;
    for(int i:r)
        arr.push_back({i,0});
    for(int i:b)
        arr.push_back({i,1});
    sort(arr.begin(),arr.end());
    
    vector<ll>dp(arr.size(),1e18);
    dp.back()=0;
    arr.emplace_back(-1,arr.back().second^1);
    int i2=(int)dp.size();
    int i3=(int)dp.size();
    for(int i1=(int)dp.size()-1;i1>=0;i1--){
        if(arr[i2].second==arr[i1].second){
            i3=i2;
            i2=i1+1;
        }
        
        if(i2==dp.size())
            continue;
        
        int mid=arr[i2].first;
        ll cost=0;
        int num1=i2-i1;
        int first1=arr[i2-1].first;
        for(int i=i1;i<i2;i++)
            cost+=mid-arr[i].first;
        
        for(int i=i2+1;i<=i3;i++){
            if(num1==0){
                cost+=arr[i-1].first-mid;
            }else{
                num1--;
                cost+=arr[i-1].first-first1;
            }
            dp[i1]=min(dp[i1],dp[i]+cost);
        }
    }
    
	return dp[0];
}

Compilation message

wiring.cpp: In function 'll min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:26:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         if(i2==dp.size())
      |            ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '25859', found: '26609'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB 3rd lines differ - on the 1st token, expected: '904', found: '905'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 3rd lines differ - on the 1st token, expected: '316', found: '307'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '27', found: '32'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '25859', found: '26609'
2 Halted 0 ms 0 KB -