Submission #341048

#TimeUsernameProblemLanguageResultExecution timeMemory
341048ant101Wiring (IOI17_wiring)C++14
30 / 100
693 ms7436 KiB
#include "wiring.h"
#include <iostream>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <assert.h>
#include <limits>
#include <cstdio>
#include <complex>
//#include "grader.cpp"
using namespace std;
long long dp[200002];
long long dp1[202][202];
long long inf  = 1e15;
long long fun(vector <int> x, vector <int> y){
    long long ans = 0;
    if(x.size() == 0 || y.size()==0)
        return inf;
    for(int i = 0 ; i <= x.size() ;i++){
        for(int j = 0 ; j <= y.size() ; j++){
            dp1[i][j]=inf;
        }
    }
    dp1[0][0]=0;
    for(int i = 0 ; i < x.size() ;i++){
        for(int j = 0 ; j < y.size() ; j++){
            dp1[i+1][j+1] = min(dp1[i][j] ,  min(dp1[i][j+1]  ,  dp1[i+1][j] ) ) + + abs(x[i] - y[j]);
        }
    }
    return dp1[x.size()][y.size()];
}

long long min_total_length(std::vector<int> r, std::vector<int> b) {
    deque < pair <int, int> > pr;
    //sort(r.begin(), r.end());
    //sort(b.begin(), b.end());
    
    int n = r.size();
    int m = b.size();
    pr.resize(n+m);
    for(int i = 0 ; i < n; i++){
        pr[i].first = r[i];
        pr[i].second = 0;
    }
    for(int i = 0 ; i < m; i++){
        pr[i+n].first = b[i];
        pr[i+n].second = 1;
    }
    sort(pr.begin(), pr.end());
    if(r.back() < b[0]){
        long long sum = 0;
        for(int i = 0 ;i < r.size(); i++)
            sum += (r.back() - r[i]);
        for(int i = 0 ;i < b.size(); i++)
            sum += (b[i] - b[0]);
        return sum + max(r.size(), b.size()) * 1ll * (b[0] - r.back());
    }
    if(n >201 || m > 201){
        for(int i = 0 ; i < n + m ; i++){
            dp[i+1]=inf;
            vector <int> r1, b1;
            for(int j  = i-1 ;j >= 0 && i-j < 13; j-- ){
                
                for(int k = j ; k <= i ;k++){
                    if(pr[k].second == 0 )
                        r1.push_back(pr[k].first);
                    else
                        b1.push_back(pr[k].first);
                }
                
                dp[i+1] = min(dp[i+1], dp[j] + fun(r1, b1));
                r1.clear();
                b1.clear();
            }
        }
        return dp[n+m];
    }
    
    return fun(r, b);
}

Compilation message (stderr)

wiring.cpp: In function 'long long int fun(std::vector<int>, std::vector<int>)':
wiring.cpp:28:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for(int i = 0 ; i <= x.size() ;i++){
      |                     ~~^~~~~~~~~~~
wiring.cpp:29:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         for(int j = 0 ; j <= y.size() ; j++){
      |                         ~~^~~~~~~~~~~
wiring.cpp:34:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for(int i = 0 ; i < x.size() ;i++){
      |                     ~~^~~~~~~~~~
wiring.cpp:35:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         for(int j = 0 ; j < y.size() ; j++){
      |                         ~~^~~~~~~~~~
wiring.cpp:25:15: warning: unused variable 'ans' [-Wunused-variable]
   25 |     long long ans = 0;
      |               ^~~
wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:61:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |         for(int i = 0 ;i < r.size(); i++)
      |                        ~~^~~~~~~~~~
wiring.cpp:63:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |         for(int i = 0 ;i < b.size(); i++)
      |                        ~~^~~~~~~~~~
#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...