Submission #20220

# Submission time Handle Problem Language Result Execution time Memory
20220 2016-04-16T13:24:05 Z erdemkiraz Palembang Bridges (APIO15_bridge) C++
Compilation error
0 ms 0 KB
#include "iostream"
#include "algorithm"
#include "vector"
#include "set"
#include "map"
#include "cstring"
#include "string"
#include "vector"
#include "cassert"
#include "queue"
#include "cstdio"
#include "cstdlib"
#include "ctime"
#include "cmath"
#include "bitset"

using namespace std;

typedef long long ll;
typedef pair < int, int > ii;

const int N = 1e5 + 5;
const int M = 100;

int n, k;
ll cnt[M], pre[N], suf[N];

void up(int l, int r, int x) {
    for(int i = l; i <= r; i++)
        cnt[i] += x;
}

void upIt(int l, int r, int x) {
    for(int i = l; i <= r; i++)
        cnt[i] += i * x;
}

ll get() {
    ll ans = 1e18;
    for(int i = 0; i < M; i++)
        ans = min(ans, cnt[i]);
    return ans;
}

int main () {
    
    scanf("%d %d", &k, &n);
    
    ll add = 0;
    
    vector < ii > v;
    
    for(int i = 1; i <= n; i++) {
        char c1, c2;
        int x, y;
        scanf(" %c %d %c %d", &c1, &x, &c2, &y);
        if(c1 == c2) {
            add += abs(x - y);
        }
        else {
            if(x > y)
                swap(x, y);
            v.push_back({x, y});
        }
    }
    
    sort(v.begin(), v.end(), [&](ii x, ii y){
        return x.first + x.second < y.first + y.second;
    });
    
    n = v.size();
    
    add += n;
    
    for(int i = 1; i <= n; i++) {
        int x = v[i - 1].first, y = v[i - 1].second;
        up(0, x, +x);
        up(x + 1, M - 1, -x);
        up(0, y, +y);
        up(y + 1, M - 1, -y);
        upIt(0, x, -2);
        upIt(y + 1, M - 1, +2);
        pre[i] = get();
    }
    
    memset(cnt, 0, sizeof(cnt));
    
    for(int i = n; i >= 1; i--) {
        int x = v[i - 1].first, y = v[i - 1].second;
        up(0, x, +x);
        up(x + 1, M - 1, -x);
        up(0, y, +y);
        up(y + 1, M - 1, -y);
        upIt(0, x, -2);
        upIt(y + 1, M - 1, +2);
        suf[i] = get();
    }
    
//    printf("pre[n] = %d add = %d\n", pre[n], add);
    
    if(k == 1)
        printf("%lld\n", pre[n] + add);
    else {
        ll ans = pre[n];
        for(int i = 1; i < n; i++)
            ans = min(ans, pre[i] + suf[i + 1]);
        printf("%lld\n", ans + add);
    }
    
    return 0;
    
}

Compilation message

bridge.cpp: In function 'int main()':
bridge.cpp:63:25: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
             v.push_back({x, y});
                         ^
bridge.cpp:63:31: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
             v.push_back({x, y});
                               ^
bridge.cpp:69:5: warning: lambda expressions only available with -std=c++11 or -std=gnu++11
     });
     ^
bridge.cpp:69:6: error: no matching function for call to 'sort(std::vector<std::pair<int, int> >::iterator, std::vector<std::pair<int, int> >::iterator, main()::<lambda(ii, ii)>)'
     });
      ^
In file included from /usr/include/c++/5/algorithm:62:0,
                 from bridge.cpp:2:
/usr/include/c++/5/bits/stl_algo.h:4689:5: note: candidate: template<class _RAIter> void std::sort(_RAIter, _RAIter)
     sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
     ^
/usr/include/c++/5/bits/stl_algo.h:4689:5: note:   template argument deduction/substitution failed:
bridge.cpp:69:6: note:   candidate expects 2 arguments, 3 provided
     });
      ^
In file included from /usr/include/c++/5/algorithm:62:0,
                 from bridge.cpp:2:
/usr/include/c++/5/bits/stl_algo.h:4718:5: note: candidate: template<class _RAIter, class _Compare> void std::sort(_RAIter, _RAIter, _Compare)
     sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
     ^
/usr/include/c++/5/bits/stl_algo.h:4718:5: note:   template argument deduction/substitution failed:
bridge.cpp: In substitution of 'template<class _RAIter, class _Compare> void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >; _Compare = main()::<lambda(ii, ii)>]':
bridge.cpp:69:6:   required from here
bridge.cpp:69:6: error: template argument for 'template<class _RAIter, class _Compare> void std::sort(_RAIter, _RAIter, _Compare)' uses local type 'main()::<lambda(ii, ii)>'
     });
      ^
bridge.cpp:69:6: error:   trying to instantiate 'template<class _RAIter, class _Compare> void std::sort(_RAIter, _RAIter, _Compare)'
bridge.cpp:47:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &k, &n);
                           ^
bridge.cpp:56:48: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf(" %c %d %c %d", &c1, &x, &c2, &y);
                                                ^