답안 #149670

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
149670 2019-09-01T06:56:10 Z rkm0959(#3623, jun6873, babo) 최적의 팀 구성 (FXCUP4_squad) C++17
컴파일 오류
0 ms 0 KB
#include "squad.h"
#include <bits/stdc++.h>
using namespace std;

using lint = long long;

struct data {
    data() {}
    data(lint x, lint y, lint i) : x(x), y(y), i(i) {}

    lint x, y, i;
    lint f(lint a, lint b) { return a*x + b*y; }
    bool operator<(const data b) const { return x < b.x or (x == b.x and y > b.y); }
};

int ccw(data a, data b, data c) {
    lint k = a.x*b.y + b.x*c.y + c.x*a.y - b.x*a.y - c.x*b.y - a.x*c.y;
    if (k>0) return 1;
    if (k<0) return -1;
    return 0;
}

struct cht {
    vector<data> v;
    void add(data p) {
        while (v.size() >= 2 and ccw(v[v.size()-2], v[v.size()-1], p) >= 0) v.pop_back();
        v.push_back(p);
    }

    data find(lint a, lint b) {
        int l = -1, r = v.size()-1;
        while (l+1<r) {
            int m = (l+r) / 2;
            if (b * (v[m+1].y - v[m].y) >= - a * (v[m+1].x - v[m].x)) l = m;
            else r = m;
        }
        return v[r];
    }

    lint second(lint a, lint b) {
        int l = -1, r = v.size()-1;
        while (l+1<r) {
            int m = (l+r) / 2;
            if (b * (v[m+1].y - v[m].y) >= - a * (v[m+1].x - v[m].x)) l = m;
            else r = m;
        }
        lint ans = 0;
        if (r > 0) ans = max(ans, v[r-1].f(a, b));
        if (r < v.size()-1) ans = max(ans, v[r+1].f(a, b));
        return ans;
    }
} a1, a2, d1, d2;

int n;
struct human {
    int a, d, p;
} a[300004];

void Init(vector<int> A, vector<int> D, vector<int> P){
    n = A.size();
    for (int i=0; i<n; i++) a[i] = (human) { A[i], D[i], P[i] };

    sort(a, a+n, [](human x, human y) { return x.a < y.a or (x.a == y.a and x.p > y.p); });
    
    for (int i=0; i<n; i++) a1.add(data(a[i].a, a[i].p, i));
    for (int i=0; i<n; i++) if (!binary_search(a1.v.begin(), a1.v.end(), data(a[i].a, a[i].p, i))) a2.add(data(a[i].a, a[i].p, i));
    
    sort(a, a+n, [](human x, human y) { return x.d < y.d or (x.d == y.d and x.p > y.p); });
    
    for (int i=0; i<n; i++) d1.add(data(a[i].d, a[i].p, i));
    for (int i=0; i<n; i++) if (!binary_search(d1.v.begin(), d1.v.end(), data(a[i].d, a[i].p, i))) d2.add(data(a[i].d, a[i].p, i));
}

long long BestSquad(int X, int Y){
    data a = a1.find(X, Y), d = d1.find(X, Y);
    if (a.i != d.i) return a.f(X, Y) + d.f(X, Y);
    else {
        lint aa = max(a1.second(X, Y), a2.find(X, Y).f(X, Y)), dd = max(d1.second(X, Y), d2.find(X, Y).f(X, Y));
        return max(a.f(X, Y) + dd, d.f(X, Y) + aa);
    }
}

Compilation message

squad.cpp:16:9: error: reference to 'data' is ambiguous
 int ccw(data a, data b, data c) {
         ^~~~
squad.cpp:7:8: note: candidates are: struct data
 struct data {
        ^~~~
In file included from /usr/include/c++/7/vector:66:0,
                 from squad.h:2,
                 from squad.cpp:1:
/usr/include/c++/7/bits/range_access.h:318:5: note:                 template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)
     data(initializer_list<_Tp> __il) noexcept
     ^~~~
/usr/include/c++/7/bits/range_access.h:309:5: note:                 template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])
     data(_Tp (&__array)[_Nm]) noexcept
     ^~~~
/usr/include/c++/7/bits/range_access.h:299:5: note:                 template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)
     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
     ^~~~
/usr/include/c++/7/bits/range_access.h:289:5: note:                 template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)
     data(_Container& __cont) noexcept(noexcept(__cont.data()))
     ^~~~
squad.cpp:16:17: error: reference to 'data' is ambiguous
 int ccw(data a, data b, data c) {
                 ^~~~
squad.cpp:7:8: note: candidates are: struct data
 struct data {
        ^~~~
In file included from /usr/include/c++/7/vector:66:0,
                 from squad.h:2,
                 from squad.cpp:1:
/usr/include/c++/7/bits/range_access.h:318:5: note:                 template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)
     data(initializer_list<_Tp> __il) noexcept
     ^~~~
/usr/include/c++/7/bits/range_access.h:309:5: note:                 template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])
     data(_Tp (&__array)[_Nm]) noexcept
     ^~~~
/usr/include/c++/7/bits/range_access.h:299:5: note:                 template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)
     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
     ^~~~
/usr/include/c++/7/bits/range_access.h:289:5: note:                 template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)
     data(_Container& __cont) noexcept(noexcept(__cont.data()))
     ^~~~
squad.cpp:16:25: error: reference to 'data' is ambiguous
 int ccw(data a, data b, data c) {
                         ^~~~
squad.cpp:7:8: note: candidates are: struct data
 struct data {
        ^~~~
In file included from /usr/include/c++/7/vector:66:0,
                 from squad.h:2,
                 from squad.cpp:1:
/usr/include/c++/7/bits/range_access.h:318:5: note:                 template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)
     data(initializer_list<_Tp> __il) noexcept
     ^~~~
/usr/include/c++/7/bits/range_access.h:309:5: note:                 template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])
     data(_Tp (&__array)[_Nm]) noexcept
     ^~~~
/usr/include/c++/7/bits/range_access.h:299:5: note:                 template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)
     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
     ^~~~
/usr/include/c++/7/bits/range_access.h:289:5: note:                 template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)
     data(_Container& __cont) noexcept(noexcept(__cont.data()))
     ^~~~
squad.cpp:16:31: error: expression list treated as compound expression in initializer [-fpermissive]
 int ccw(data a, data b, data c) {
                               ^
squad.cpp:24:16: error: template argument 1 is invalid
     vector<data> v;
                ^
squad.cpp:24:16: error: template argument 2 is invalid
squad.cpp:25:14: error: reference to 'data' is ambiguous
     void add(data p) {
              ^~~~
squad.cpp:7:8: note: candidates are: struct data
 struct data {
        ^~~~
In file included from /usr/include/c++/7/vector:66:0,
                 from squad.h:2,
                 from squad.cpp:1:
/usr/include/c++/7/bits/range_access.h:318:5: note:                 template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)
     data(initializer_list<_Tp> __il) noexcept
     ^~~~
/usr/include/c++/7/bits/range_access.h:309:5: note:                 template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])
     data(_Tp (&__array)[_Nm]) noexcept
     ^~~~
/usr/include/c++/7/bits/range_access.h:299:5: note:                 template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)
     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
     ^~~~
/usr/include/c++/7/bits/range_access.h:289:5: note:                 template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)
     data(_Container& __cont) noexcept(noexcept(__cont.data()))
     ^~~~
squad.cpp:25:14: error: 'data' has not been declared
     void add(data p) {
              ^~~~
squad.cpp:30:5: error: reference to 'data' is ambiguous
     data find(lint a, lint b) {
     ^~~~
squad.cpp:7:8: note: candidates are: struct data
 struct data {
        ^~~~
In file included from /usr/include/c++/7/vector:66:0,
                 from squad.h:2,
                 from squad.cpp:1:
/usr/include/c++/7/bits/range_access.h:318:5: note:                 template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)
     data(initializer_list<_Tp> __il) noexcept
     ^~~~
/usr/include/c++/7/bits/range_access.h:309:5: note:                 template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])
     data(_Tp (&__array)[_Nm]) noexcept
     ^~~~
/usr/include/c++/7/bits/range_access.h:299:5: note:                 template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)
     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
     ^~~~
/usr/include/c++/7/bits/range_access.h:289:5: note:                 template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)
     data(_Container& __cont) noexcept(noexcept(__cont.data()))
     ^~~~
squad.cpp: In member function 'void cht::add(int)':
squad.cpp:26:18: error: request for member 'size' in '((cht*)this)->cht::v', which is of non-class type 'int'
         while (v.size() >= 2 and ccw(v[v.size()-2], v[v.size()-1], p) >= 0) v.pop_back();
                  ^~~~
squad.cpp:26:42: error: request for member 'size' in '((cht*)this)->cht::v', which is of non-class type 'int'
         while (v.size() >= 2 and ccw(v[v.size()-2], v[v.size()-1], p) >= 0) v.pop_back();
                                          ^~~~
squad.cpp:26:57: error: request for member 'size' in '((cht*)this)->cht::v', which is of non-class type 'int'
         while (v.size() >= 2 and ccw(v[v.size()-2], v[v.size()-1], p) >= 0) v.pop_back();
                                                         ^~~~
squad.cpp:26:69: error: 'ccw' cannot be used as a function
         while (v.size() >= 2 and ccw(v[v.size()-2], v[v.size()-1], p) >= 0) v.pop_back();
                                                                     ^
squad.cpp:26:79: error: request for member 'pop_back' in '((cht*)this)->cht::v', which is of non-class type 'int'
         while (v.size() >= 2 and ccw(v[v.size()-2], v[v.size()-1], p) >= 0) v.pop_back();
                                                                               ^~~~~~~~
squad.cpp:27:11: error: request for member 'push_back' in '((cht*)this)->cht::v', which is of non-class type 'int'
         v.push_back(p);
           ^~~~~~~~~
squad.cpp: In member function 'lint cht::second(lint, lint)':
squad.cpp:41:27: error: request for member 'size' in '((cht*)this)->cht::v', which is of non-class type 'int'
         int l = -1, r = v.size()-1;
                           ^~~~
squad.cpp:44:27: error: invalid types 'int[int]' for array subscript
             if (b * (v[m+1].y - v[m].y) >= - a * (v[m+1].x - v[m].x)) l = m;
                           ^
squad.cpp:44:36: error: invalid types 'int[int]' for array subscript
             if (b * (v[m+1].y - v[m].y) >= - a * (v[m+1].x - v[m].x)) l = m;
                                    ^
squad.cpp:44:56: error: invalid types 'int[int]' for array subscript
             if (b * (v[m+1].y - v[m].y) >= - a * (v[m+1].x - v[m].x)) l = m;
                                                        ^
squad.cpp:44:65: error: invalid types 'int[int]' for array subscript
             if (b * (v[m+1].y - v[m].y) >= - a * (v[m+1].x - v[m].x)) l = m;
                                                                 ^
squad.cpp:48:40: error: invalid types 'int[int]' for array subscript
         if (r > 0) ans = max(ans, v[r-1].f(a, b));
                                        ^
squad.cpp:49:19: error: request for member 'size' in '((cht*)this)->cht::v', which is of non-class type 'int'
         if (r < v.size()-1) ans = max(ans, v[r+1].f(a, b));
                   ^~~~
squad.cpp:49:49: error: invalid types 'int[int]' for array subscript
         if (r < v.size()-1) ans = max(ans, v[r+1].f(a, b));
                                                 ^
squad.cpp: In function 'void Init(std::vector<int>, std::vector<int>, std::vector<int>)':
squad.cpp:65:36: error: reference to 'data' is ambiguous
     for (int i=0; i<n; i++) a1.add(data(a[i].a, a[i].p, i));
                                    ^~~~
squad.cpp:7:8: note: candidates are: struct data
 struct data {
        ^~~~
In file included from /usr/include/c++/7/vector:66:0,
                 from squad.h:2,
                 from squad.cpp:1:
/usr/include/c++/7/bits/range_access.h:318:5: note:                 template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)
     data(initializer_list<_Tp> __il) noexcept
     ^~~~
/usr/include/c++/7/bits/range_access.h:309:5: note:                 template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])
     data(_Tp (&__array)[_Nm]) noexcept
     ^~~~
/usr/include/c++/7/bits/range_access.h:299:5: note:                 template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)
     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
     ^~~~
/usr/include/c++/7/bits/range_access.h:289:5: note:                 template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)
     data(_Container& __cont) noexcept(noexcept(__cont.data()))
     ^~~~
squad.cpp:66:53: error: request for member 'begin' in 'a1.cht::v', which is of non-class type 'int'
     for (int i=0; i<n; i++) if (!binary_search(a1.v.begin(), a1.v.end(), data(a[i].a, a[i].p, i))) a2.add(data(a[i].a, a[i].p, i));
                                                     ^~~~~
squad.cpp:66:67: error: request for member 'end' in 'a1.cht::v', which is of non-class type 'int'
     for (int i=0; i<n; i++) if (!binary_search(a1.v.begin(), a1.v.end(), data(a[i].a, a[i].p, i))) a2.add(data(a[i].a, a[i].p, i));
                                                                   ^~~
squad.cpp:66:74: error: reference to 'data' is ambiguous
     for (int i=0; i<n; i++) if (!binary_search(a1.v.begin(), a1.v.end(), data(a[i].a, a[i].p, i))) a2.add(data(a[i].a, a[i].p, i));
                                                                          ^~~~
squad.cpp:7:8: note: candidates are: struct data
 struct data {
        ^~~~
In file included from /usr/include/c++/7/vector:66:0,
                 from squad.h:2,
                 from squad.cpp:1:
/usr/include/c++/7/bits/range_access.h:318:5: note:                 template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)
     data(initializer_list<_Tp> __il) noexcept
     ^~~~
/usr/include/c++/7/bits/range_access.h:309:5: note:                 template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])
     data(_Tp (&__array)[_Nm]) noexcept
     ^~~~
/usr/include/c++/7/bits/range_access.h:299:5: note:                 template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)
     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
     ^~~~
/usr/include/c++/7/bits/range_access.h:289:5: note:                 template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)
     data(_Container& __cont) noexcept(noexcept(__cont.data()))
     ^~~~
squad.cpp:66:107: error: reference to 'data' is ambiguous
     for (int i=0; i<n; i++) if (!binary_search(a1.v.begin(), a1.v.end(), data(a[i].a, a[i].p, i))) a2.add(data(a[i].a, a[i].p, i));
                                                                                                           ^~~~
squad.cpp:7:8: note: candidates are: struct data
 struct data {
        ^~~~
In file included from /usr/include/c++/7/vector:66:0,
                 from squad.h:2,
                 from squad.cpp:1:
/usr/include/c++/7/bits/range_access.h:318:5: note:                 template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)
     data(initializer_list<_Tp> __il) noexcept
     ^~~~
/usr/include/c++/7/bits/range_access.h:309:5: note:                 template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])
     data(_Tp (&__array)[_Nm]) noexcept
     ^~~~
/usr/include/c++/7/bits/range_access.h:299:5: note:                 template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)
     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
     ^~~~
/usr/include/c++/7/bits/range_access.h:289:5: note:                 template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)
     data(_Container& __cont) noexcept(noexcept(__cont.data()))
     ^~~~
squad.cpp:70:36: error: reference to 'data' is ambiguous
     for (int i=0; i<n; i++) d1.add(data(a[i].d, a[i].p, i));
                                    ^~~~
squad.cpp:7:8: note: candidates are: struct data
 struct data {
        ^~~~
In file included from /usr/include/c++/7/vector:66:0,
                 from squad.h:2,
                 from squad.cpp:1:
/usr/include/c++/7/bits/range_access.h:318:5: note:                 template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)
     data(initializer_list<_Tp> __il) noexcept
     ^~~~
/usr/include/c++/7/bits/range_access.h:309:5: note:                 template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])
     data(_Tp (&__array)[_Nm]) noexcept
     ^~~~
/usr/include/c++/7/bits/range_access.h:299:5: note:                 template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)
     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
     ^~~~
/usr/include/c++/7/bits/range_access.h:289:5: note:                 template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)
     data(_Container& __cont) noexcept(noexcept(__cont.data()))
     ^~~~
squad.cpp:71:53: error: request for member 'begin' in 'd1.cht::v', which is of non-class type 'int'
     for (int i=0; i<n; i++) if (!binary_search(d1.v.begin(), d1.v.end(), data(a[i].d, a[i].p, i))) d2.add(data(a[i].d, a[i].p, i));
                                                     ^~~~~
squad.cpp:71:67: error: request for member 'end' in 'd1.cht::v', which is of non-class type 'int'
     for (int i=0; i<n; i++) if (!binary_search(d1.v.begin(), d1.v.end(), data(a[i].d, a[i].p, i))) d2.add(data(a[i].d, a[i].p, i));
                                                                   ^~~
squad.cpp:71:74: error: reference to 'data' is ambiguous
     for (int i=0; i<n; i++) if (!binary_search(d1.v.begin(), d1.v.end(), data(a[i].d, a[i].p, i))) d2.add(data(a[i].d, a[i].p, i));
                                                                          ^~~~
squad.cpp:7:8: note: candidates are: struct data
 struct data {
        ^~~~
In file included from /usr/include/c++/7/vector:66:0,
                 from squad.h:2,
                 from squad.cpp:1:
/usr/include/c++/7/bits/range_access.h:318:5: note:                 template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)
     data(initializer_list<_Tp> __il) noexcept
     ^~~~
/usr/include/c++/7/bits/range_access.h:309:5: note:                 template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])
     data(_Tp (&__array)[_Nm]) noexcept
     ^~~~
/usr/include/c++/7/bits/range_access.h:299:5: note:                 template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)
     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
     ^~~~
/usr/include/c++/7/bits/range_access.h:289:5: note:                 template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)
     data(_Container& __cont) noexcept(noexcept(__cont.data()))
     ^~~~
squad.cpp:71:107: error: reference to 'data' is ambiguous
     for (int i=0; i<n; i++) if (!binary_search(d1.v.begin(), d1.v.end(), data(a[i].d, a[i].p, i))) d2.add(data(a[i].d, a[i].p, i));
                                                                                                           ^~~~
squad.cpp:7:8: note: candidates are: struct data
 struct data {
        ^~~~
In file included from /usr/include/c++/7/vector:66:0,
                 from squad.h:2,
                 from squad.cpp:1:
/usr/include/c++/7/bits/range_access.h:318:5: note:                 template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)
     data(initializer_list<_Tp> __il) noexcept
     ^~~~
/usr/include/c++/7/bits/range_access.h:309:5: note:                 template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])