Submission #988924

#TimeUsernameProblemLanguageResultExecution timeMemory
988924steveonalexWiring (IOI17_wiring)C++17
7 / 100
1070 ms15984 KiB
#include <bits/stdc++.h>
#include "wiring.h"
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define MASK(i) (1ULL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
 
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
 
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}
 
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
 
template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b) {a = b; return true;}
        return false;
    }
 
template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b) {a = b; return true;}
        return false;
    }
 
template <class T>
    void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){
        for(auto item: container) out << item << separator;
        out << finish;
    }
 
template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }
 
const int N = 2002;
const ll INF = 1e18 + 69;
 
int n, m;

vector<ll> dp[N];
vector<ll> bruh[N];
 
ll min_total_length(vector<int> a, vector<int> b) {
    n = a.size(), m = b.size();
    vector<pair<int, int>> point;
    for(int i: a) point.push_back({i, 0});
    for(int i: b) point.push_back({i, 1});

    sort(ALL(point));   
    vector<vector<int>> component;
    for(int i = 0; i<point.size(); ++i){
        if (i == 0) {
            component.push_back({point[i].first});
        }
        else{
            if (point[i].second != point[i-1].second){
                component.push_back({point[i].first});
            }
            else component.back().push_back(point[i].first);
        }
    }

    int k = component.size();
    for(int i = 0; i<k; ++i){
        dp[i].resize(component[i].size() + 1, INF);
    }

    for(int i = 0; i<k; ++i){
        bruh[i].resize(component[i].size() + 1, 0);

        ll s = 0;
        for(int j = 0; j < component[i].size(); ++j){
            s += abs(component[i][j] - component[i][0]);
            bruh[i][j+1] += s;
        }

        s = 0;
        for(int j = component[i].size() - 1; j>=0; --j){
            s += abs(component[i].back() - component[i][j]);
            bruh[i][j] += s;
        }
    }

    for(int j = 1; j < bruh[0].size(); ++j) bruh[0][j] = INF;
    for(int j = 0; j+1 < bruh[k-1].size(); ++j) bruh[k-1][j] = INF;
    dp[0][0] = bruh[0][0];


    for(int i = 1; i<k; ++i){
        for(int j = 0; j < dp[i].size(); ++j)
        for(int t = 0; t < dp[i-1].size(); ++t){
            ll cur = dp[i-1][t] + bruh[i][j];
            cur += 1LL * (component[i][0] - component[i-1].back()) * max(j, dp[i-1].size() - t - 1);
            minimize(dp[i][j], cur);
        }
    }

    return dp[k-1].back();
}
 
// int main(void){
//     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
//     int n, m; cin >> n >> m;
//     vector<int> a(n), b(m);
//     for(int i = 0 ; i<n; ++i) cin >> a[i];
//     for(int j = 0; j<m; ++j) cin >> b[j];
//     cout << min_total_length(a, b) << "\n";
    
 
//     return 0;
// }

Compilation message (stderr)

wiring.cpp: In function 'll min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:64:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |     for(int i = 0; i<point.size(); ++i){
      |                    ~^~~~~~~~~~~~~
wiring.cpp:85:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |         for(int j = 0; j < component[i].size(); ++j){
      |                        ~~^~~~~~~~~~~~~~~~~~~~~
wiring.cpp:97:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |     for(int j = 1; j < bruh[0].size(); ++j) bruh[0][j] = INF;
      |                    ~~^~~~~~~~~~~~~~~~
wiring.cpp:98:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |     for(int j = 0; j+1 < bruh[k-1].size(); ++j) bruh[k-1][j] = INF;
      |                    ~~~~^~~~~~~~~~~~~~~~~~
wiring.cpp:103:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |         for(int j = 0; j < dp[i].size(); ++j)
      |                        ~~^~~~~~~~~~~~~~
wiring.cpp:104:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |         for(int t = 0; t < dp[i-1].size(); ++t){
      |                        ~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...