Submission #25019

# Submission time Handle Problem Language Result Execution time Memory
25019 2017-06-20T04:17:03 Z 윤교준(#1055) Palembang Bridges (APIO15_bridge) C++
Compilation error
0 ms 0 KB
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#define pb push_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[(sz(V)-2)])
#define sorv(V) sort(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define INF (1100000099)
#define INFLL (1100000000000000099ll)
#define MAXN (100005)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
inline ll myabs(const ll& n) { return n < 0 ? -n : n; }

ll d[2][MAXN];
int A[MAXN], B[MAXN], P[MAXN];
int N, K;
ll Ans;

void input() {
    scanf("%d%d", &K, &N);
    int cnt = 0; for(int i = 0; i < N; i++) {
        int x, y; char a, b; scanf(" %c%d %c%d", &a, &x, &b, &y);
        if(a == b) { Ans += myabs(x-y); continue; }
        A[cnt] = x; B[cnt] = y; cnt++;
    }
    N = cnt;
}
void process1() {
    vector<int> V;
    for(int i = 0; i < N; i++) { V.pb(A[i]); V.pb(B[i]); }
    sorv(V); const int X = V[sz(V)/2];
    for(int i = 0; i < N; i++) Ans += myabs((ll)A[i] - X) + myabs((ll)B[i] - X);
    Ans += sz(V)/2;
}
multiset<int> Q;
void meanF(ll d[]) {
    multiset<int>().swap(Q);
    Q.insert(A[P[0]]); Q.insert(B[P[0]]);
    auto it = Q.begin(); d[0] = myabs((ll)A[P[0]] - (*it)) + myabs((ll)B[P[0]] - (*it));
    for(int p_i = 1; p_i < N; p_i++) {
        const int &idx = P[p_i]; ll &ret = d[p_i];
        if(A[idx] > B[idx]) swap(A[idx], B[idx]);
        if(B[idx] <= (*it)) {
            const int prv = *it;
            Q.insert(A[idx]); Q.insert(B[idx]);
            it--; ret = d[p_i-1] + (ll)(*it)*2 - A[idx] - B[idx] + ((ll)prv-(*it))*2;
        } else if((*it) <= A[idx]) {
            Q.insert(A[idx]); Q.insert(B[idx]);
            it++; ret = d[p_i-1] + A[idx] + B[idx] - (ll)(*it)*2;
        } else {
            Q.insert(A[idx]); Q.insert(B[idx]);
            ret = d[p_i-1] + B[idx] - A[idx];
        }
    }
}
void process2() {
    for(int i = 0; i < N; i++) P[i] = i;
    sort(P, P+N, [&](const int& a, const int& b) -> bool {
        return (A[a]+B[a]) < (A[b]+B[b]);
    });
    meanF(d[0]); reverse(P, P+N); meanF(d[1]); reverse(d[1], d[1]+N); reverse(P, P+N);

    ll ret = d[0][0] + d[1][1];

    for(int i = 0; i+1 < N; i++) {
        upmin(ret, d[0][i] + d[1][i+1]);
    }
    upmin(ret, d[0][3]); upmin(ret, d[1][0]);
    Ans += ret + N;
}
int main() {
    input();
    if(!N); else if(1 == N) { Ans += myabs(A[0] - B[0]); }
    else if(1 == K) process1(); else process2();
    printf("%lld\n", Ans);
    return 0;
}

Compilation message

In file included from /usr/include/c++/5/unordered_map:35:0,
                 from bridge.cpp:13:
/usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support \
  ^
bridge.cpp: In function 'void meanF(ll*)':
bridge.cpp:60:5: warning: 'auto' changes meaning in C++11; please remove it [-Wc++0x-compat]
     auto it = Q.begin(); d[0] = myabs((ll)A[P[0]] - (*it)) + myabs((ll)B[P[0]] - (*it));
     ^
bridge.cpp:60:10: error: 'it' does not name a type
     auto it = Q.begin(); d[0] = myabs((ll)A[P[0]] - (*it)) + myabs((ll)B[P[0]] - (*it));
          ^
bridge.cpp:60:55: error: 'it' was not declared in this scope
     auto it = Q.begin(); d[0] = myabs((ll)A[P[0]] - (*it)) + myabs((ll)B[P[0]] - (*it));
                                                       ^
bridge.cpp: In function 'void process2()':
bridge.cpp:81:5: warning: lambda expressions only available with -std=c++11 or -std=gnu++11
     });
     ^
bridge.cpp:81:6: error: no matching function for call to 'sort(int [100005], int*, process2()::<lambda(const int&, const int&)>)'
     });
      ^
In file included from /usr/include/c++/5/algorithm:62:0,
                 from bridge.cpp:6:
/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:81:6: note:   candidate expects 2 arguments, 3 provided
     });
      ^
In file included from /usr/include/c++/5/algorithm:62:0,
                 from bridge.cpp:6:
/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 = int*; _Compare = process2()::<lambda(const int&, const int&)>]':
bridge.cpp:81:6:   required from here
bridge.cpp:81:6: error: template argument for 'template<class _RAIter, class _Compare> void std::sort(_RAIter, _RAIter, _Compare)' uses local type 'process2()::<lambda(const int&, const int&)>'
     });
      ^
bridge.cpp:81:6: error:   trying to instantiate 'template<class _RAIter, class _Compare> void std::sort(_RAIter, _RAIter, _Compare)'
bridge.cpp: In function 'void input()':
bridge.cpp:41:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &K, &N);
                          ^
bridge.cpp:43:65: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         int x, y; char a, b; scanf(" %c%d %c%d", &a, &x, &b, &y);
                                                                 ^