Submission #583757

#TimeUsernameProblemLanguageResultExecution timeMemory
583757MohamedFaresNebiliWiring (IOI17_wiring)C++14
0 / 100
1084 ms4056 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

        using namespace std;
        using namespace __gnu_pbds;

        using ll = long long;
        using pi = pair<ll, pair<ll, ll>>;
        using ii = pair<ll, ll>;

        #define pb push_back
        #define pp pop_back
        #define ff first
        #define ss second
        #define lb lower_bound

        typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update> indexed_set;

        ll min_total_length(vector<int> R, vector<int> B) {
            int N = R.size(), M = B.size(), res = 0;
            vector<pair<int, int>> arr(N + M);
            for(int l = 0; l < N; l++) arr[l] = {R[l], 1};
            for(int l = 0; l < M; l++) arr[l + N] = {B[l], 0};
            sort(arr.begin(), arr.end());
            vector<bool> vis(N + M, 0);
            for(int l = 0; l < N + M; l++) {
                if(vis[l]) continue;
                bool matched = 0;
                for(int i = l + 1; i < N + M; i++) {
                    if(vis[i] || arr[l].ss == arr[i].ss)
                        continue;
                    matched = 1; vis[i] = 1;
                    res += arr[i].ff - arr[l].ff;
                    break;
                }
                vis[l] = matched;
            }
            for(int l = 0; l < N + M; l++) {
                if(vis[l]) continue;
                int curr = 1e9 + 7;
                for(int i = 0; i < N + M; i++) {
                    if(arr[l].ss == arr[i].ss)
                        continue;
                    int calc = abs(arr[i].ff - arr[l].ff);
                    if(calc < curr)
                        curr = calc;
                }
                res += curr;
            }
            return res;
        }
#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...