Submission #612528

#TimeUsernameProblemLanguageResultExecution timeMemory
612528MohamedAliSaidaneWiring (IOI17_wiring)C++14
7 / 100
27 ms6088 KiB
#include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef double ld;
    typedef pair<int,int> pii;
    typedef pair<ll,ll> pll;

    typedef vector<int> vi;
    typedef vector<ll> vll;
    typedef vector<pii> vpi;
    typedef vector<pll> vpl;

    #define pb push_back
    #define popb pop_back
    #define all(x) (x).begin(),(x).end()

    #define ff first
    #define ss second

    const int nax = 205;
    const ll INF = 1e18;
    int n, m;
    vll A, B;
    ll dp[nax][nax];
    int f(int i, int j)
    {
        if(i >= n && j >= m)
            return 0ll;
        if(dp[i][j] != -1)
            return dp[i][j];
        ll br = INF, rb = INF, bt = INF ;
        if(j != 0 && i != n)
            br = f(i + 1,j) + abs(A[i] - B[j - 1]);
        if(i != 0 && j != n)
            rb = f(i, j + 1) + abs(A[i - 1] - B[j]);
        if(i != n && j != n)
            bt = f(i +1, j+ 1) + abs(A[i] - B[j]);

        return dp[i][j] = min(bt,min(rb, br));
    }
    ll min_total_length(vi r, vi b)
    {
        n = r.size(), m = b.size();
        sort(all(r));
        sort(all(b));
        for(auto e: r)
            A.pb(e);
        for(auto e: b)
            B.pb(e);
        memset(dp, -1,sizeof(dp));
        return f(0, 0);

    }
#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...