Submission #731412

#TimeUsernameProblemLanguageResultExecution timeMemory
731412LucaIlieWiring (IOI17_wiring)C++17
13 / 100
30 ms2248 KiB
#include "wiring.h"
#include <bits/stdc++.h>

using namespace std;

long long min_total_length( vector<int> r, vector<int> b ) {
    int i = 0, j = 0;
    long long cost = 0;
    queue<int> q;

    while ( i < r.size() && j < b.size() ) {
        if ( r[i] < b[j] ) {
            if ( i < j ) {
                cost += r[i] - q.front(), printf( "%d %d\n", r[i], q.front() );
                q.pop();
            } else
                q.push( r[i] );
            i++;
        } else {
            if ( j < i ) {
                cost += b[j] - q.front(), printf( "%d %d\n", b[j], q.front() );;
                q.pop();
            } else
                q.push( b[j] );
            j++;
        }
    }
    while ( i < r.size() ) {
        if ( !q.empty() ) {
            cost += r[i] - q.front();
            q.pop();
        } else
            cost += r[i] - b.back();
        i++;
    }
    while ( j < b.size() ) {
        if ( !q.empty() ) {
            cost += b[j] - q.front();
            q.pop();
        } else
            cost += b[j] - r.back();
        j++;
    }

    if ( q.empty() )
        return cost;
    i = 0, j = 0;
    cost = 0;
    while ( !q.empty() )
        q.pop();
    reverse( r.begin(), r.end() );
    reverse( b.begin(), b.end() );

    while ( i < r.size() && j < b.size() ) {
        if ( r[i] > b[j] ) {
            if ( i < j ) {
                cost += r[i] - q.front();
                q.pop();
            } else
                q.push( r[i] );
            i++;
        } else {
            if ( j < i ) {
                cost += b[j] - q.front();
                q.pop();
            } else
                q.push( b[j] );
            j++;
        }
    }
    while ( i < r.size() ) {
        if ( !q.empty() ) {
            cost += r[i] - q.front();
            q.pop();
        } else
            cost += r[i] - b.back();
        i++;
    }
    while ( j < b.size() ) {
        if ( !q.empty() ) {
            cost += b[j] - q.front();
            q.pop();
        } else
            cost += b[j] - r.back();
        j++;
    }

    return -cost;
}

Compilation message (stderr)

wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:11:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     while ( i < r.size() && j < b.size() ) {
      |             ~~^~~~~~~~~~
wiring.cpp:11:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     while ( i < r.size() && j < b.size() ) {
      |                             ~~^~~~~~~~~~
wiring.cpp:28:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     while ( i < r.size() ) {
      |             ~~^~~~~~~~~~
wiring.cpp:36:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     while ( j < b.size() ) {
      |             ~~^~~~~~~~~~
wiring.cpp:54:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     while ( i < r.size() && j < b.size() ) {
      |             ~~^~~~~~~~~~
wiring.cpp:54:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     while ( i < r.size() && j < b.size() ) {
      |                             ~~^~~~~~~~~~
wiring.cpp:71:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |     while ( i < r.size() ) {
      |             ~~^~~~~~~~~~
wiring.cpp:79:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |     while ( j < b.size() ) {
      |             ~~^~~~~~~~~~
#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...