제출 #1181180

#제출 시각아이디문제언어결과실행 시간메모리
1181180steveonalexPortal (BOI24_portal)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define MASK(i) (1ULL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll gcd(ll a, ll b){return __gcd(abs(a), abs(b));}
ll lcm(ll a, ll b){return abs(a) / gcd(a, b) * abs(b);}

ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ull mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}

mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}

template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b) {a = b; return true;}
        return false;
    }

template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b) {a = b; return true;}
        return false;
    }

template <class T>
    void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){
        for(auto item: container) out << item << separator;
        out << finish;
    }

template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }

#define lll __int128

vector<pair<lll,lll>> gg;

lll abs(lll a){
    return (a < 0) ? (-a) : a;
}

lll gcd(lll a, lll b){
    while(a > 0 && b > 0){
        tie(a, b) = make_pair(b % a, a);
    }
    return a + b;
}

void make_positive(pair<lll, lll> &a){
    if (a.first < 0){
        a = make_pair(-a.first, -a.second);
    }
    else if (a.first == 0 && a.second < 0){
        a = make_pair(-a.first, -a.second);
    }
}

void vector_gcd(pair<lll, lll> &a, pair<lll, lll> &b){
    while(a.first != 0){
        make_positive(a);
        make_positive(b);

        lll d = b.first / a.first;
        b.first -= a.first * d;
        b.second -= a.second * d;

        swap(a, b);
    }
    make_positive(a);
    make_positive(b);
}

void update(pair<lll, lll> v){
    for(pair<lll, lll> &i: gg){
        if (i.first * v.second == i.second * v.first){
            lll x1 = abs(i.first + i.second);
            lll x2 = abs(v.first + v.second);
            lll g = gcd(x1, x2);

            i.first /= (x1 / g);
            i.second /= (x1 / g);

            return;
        }
    }

    if (gg.size() < 2) {
        gg.push_back(v);
        if (gg.size() == 2){
            vector_gcd(gg[0], gg[1]);
        }
        return;
    }

    vector_gcd(gg[0], v);
    vector_gcd(gg[1], v);
    lll g = gcd(abs(gg[0].second), abs(gg[1].second));
    gg.clear();
    gg.push_back(make_pair(0, g));
    gg.push_back(v);
}

ll solve(){
    int n; cin >> n;
    vector<pair<ll, ll>> a(n);
    for(int i = 0; i < n; ++i) cin >> a[i].first >> a[i].second;

    sort(ALL(a));

    vector<pair<ll,ll>> b;
    for(int i = 1; i < n; ++i){
        b.push_back(make_pair(a[i].first - a[0].first, a[i].second - a[0].second));
    }

    for(pair<ll, ll> i: b){
        pair<lll, lll> tmp = make_pair((lll)i.first, (lll)i.second);
        update(tmp);
    }

    if (gg.size() < 2){
        return -1;
    }
    else{
        ll y = gg[0].second;
        ll x = 0;
        for(pair<ll, ll> i: b) x = gcd(x, abs(i.first));

        return x * y;
    }
}

int main(void){
    ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);

    clock_t start = clock();

    cout << solve() << "\n";

    cerr << "Time elapsed: " << clock() - start << "ms!\n";
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'void update(std::pair<__int128, __int128>)':
Main.cpp:91:25: error: call of overloaded 'abs(__int128)' is ambiguous
   91 |             lll x1 = abs(i.first + i.second);
      |                      ~~~^~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/std_abs.h:38,
                 from /usr/include/c++/11/cmath:47,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from Main.cpp:1:
/usr/include/stdlib.h:848:12: note: candidate: 'int abs(int)'
  848 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
Main.cpp:53:5: note: candidate: '__int128 abs(__int128)'
   53 | lll abs(lll a){
      |     ^~~
In file included from /usr/include/c++/11/cmath:47,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from Main.cpp:1:
/usr/include/c++/11/bits/std_abs.h:103:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
  103 |   abs(__float128 __x)
      |   ^~~
/usr/include/c++/11/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
   85 |   abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
      |   ^~~
/usr/include/c++/11/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
   79 |   abs(long double __x)
      |   ^~~
/usr/include/c++/11/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
   75 |   abs(float __x)
      |   ^~~
/usr/include/c++/11/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
   71 |   abs(double __x)
      |   ^~~
/usr/include/c++/11/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
   61 |   abs(long long __x) { return __builtin_llabs (__x); }
      |   ^~~
/usr/include/c++/11/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |   ^~~
Main.cpp:92:25: error: call of overloaded 'abs(__int128)' is ambiguous
   92 |             lll x2 = abs(v.first + v.second);
      |                      ~~~^~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/std_abs.h:38,
                 from /usr/include/c++/11/cmath:47,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from Main.cpp:1:
/usr/include/stdlib.h:848:12: note: candidate: 'int abs(int)'
  848 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
Main.cpp:53:5: note: candidate: '__int128 abs(__int128)'
   53 | lll abs(lll a){
      |     ^~~
In file included from /usr/include/c++/11/cmath:47,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from Main.cpp:1:
/usr/include/c++/11/bits/std_abs.h:103:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
  103 |   abs(__float128 __x)
      |   ^~~
/usr/include/c++/11/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
   85 |   abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
      |   ^~~
/usr/include/c++/11/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
   79 |   abs(long double __x)
      |   ^~~
/usr/include/c++/11/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
   75 |   abs(float __x)
      |   ^~~
/usr/include/c++/11/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
   71 |   abs(double __x)
      |   ^~~
/usr/include/c++/11/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
   61 |   abs(long long __x) { return __builtin_llabs (__x); }
      |   ^~~
/usr/include/c++/11/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |   ^~~
Main.cpp:112:20: error: call of overloaded 'abs(__int128&)' is ambiguous
  112 |     lll g = gcd(abs(gg[0].second), abs(gg[1].second));
      |                 ~~~^~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/std_abs.h:38,
                 from /usr/include/c++/11/cmath:47,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from Main.cpp:1:
/usr/include/stdlib.h:848:12: note: candidate: 'int abs(int)'
  848 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
Main.cpp:53:5: note: candidate: '__int128 abs(__int128)'
   53 | lll abs(lll a){
      |     ^~~
In file included from /usr/include/c++/11/cmath:47,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from Main.cpp:1:
/usr/include/c++/11/bits/std_abs.h:103:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
  103 |   abs(__float128 __x)
      |   ^~~
/usr/include/c++/11/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
   85 |   abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
      |   ^~~
/usr/include/c++/11/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
   79 |   abs(long double __x)
      |   ^~~
/usr/include/c++/11/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
   75 |   abs(float __x)
      |   ^~~
/usr/include/c++/11/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
   71 |   abs(double __x)
      |   ^~~
/usr/include/c++/11/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
   61 |   abs(long long __x) { return __builtin_llabs (__x); }
      |   ^~~
/usr/include/c++/11/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |   ^~~
Main.cpp:112:39: error: call of overloaded 'abs(__int128&)' is ambiguous
  112 |     lll g = gcd(abs(gg[0].second), abs(gg[1].second));
      |                                    ~~~^~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/std_abs.h:38,
                 from /usr/include/c++/11/cmath:47,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from Main.cpp:1:
/usr/include/stdlib.h:848:12: note: candidate: 'int abs(int)'
  848 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
Main.cpp:53:5: note: candidate: '__int128 abs(__int128)'
   53 | lll abs(lll a){
      |     ^~~
In file included from /usr/include/c++/11/cmath:47,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from Main.cpp:1:
/usr/include/c++/11/bits/std_abs.h:103:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
  103 |   abs(__float128 __x)
      |   ^~~
/usr/include/c++/11/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
   85 |   abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
      |   ^~~
/usr/include/c++/11/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
   79 |   abs(long double __x)
      |   ^~~
/usr/include/c++/11/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
   75 |   abs(float __x)
      |   ^~~
/usr/include/c++/11/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
   71 |   abs(double __x)
      |   ^~~
/usr/include/c++/11/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
   61 |   abs(long long __x) { return __builtin_llabs (__x); }
      |   ^~~
/usr/include/c++/11/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |   ^~~