Submission #542552

# Submission time Handle Problem Language Result Execution time Memory
542552 2022-03-26T22:52:43 Z Olympia Drzava (COCI15_drzava) C++17
Compilation error
0 ms 0 KB
#include <vector>
#include <algorithm>
#include <iostream>
#include <set>
#include <cmath>
#include <map>
#include <random>
#include <cassert>
#include <ctime>
#include <iomanip>
#include <unordered_map>
#include <cstdlib>
#include <queue>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O2")
#pragma GCC optimization ("unroll-loops")
#include <limits.h>
using namespace std;
int lst = 0;
class DisjointSetUnion {
protected:
    vector<int> parent;
    vector<int> compSize;
    int k;
    vector<vector<int>> pos;
    int n;
    int connectedComponents;
public:
    int getConnectedComponents() const {
        return connectedComponents;
    }

public:
    vector<int> merge (vector<int> a1, vector<int> a2) {
        vector<int> a(a1.size());
        a.resize(a1.size(), 0);
        for (int i = 0; i < a1.size(); i++) {
            for (int j = 0; j < a2.size(); j++) {
                a[(i + j) % k] += a1[i] * a2[j];
            }
        }
        if (a[0] > 1) {
            cout << fixed << setprecision(3) << sqrt(lst) << '\n';
            exit(0);
        }
        return a;
    }
    DisjointSetUnion(vector<int64_t> arr, int sz, int K) {
        n = sz;
        parent.resize(sz), compSize.resize(sz);
        for (int i = 0; i < n; i++) {
            parent[i] = i, compSize[i] = 1;
        }
        this->k = K;
        pos.resize(sz);
        for (int i = 0; i < sz; i++) {
            pos[i].assign(k, false);
            pos[i][arr[i] % k] = true;
            pos[i][0] = true;
        }
    }

    int find_head(int x) const {
        int cur = x;
        while (cur != parent[cur]) {
            cur = parent[cur];
        }
        return cur;
    }

    void join(int x, int y) {
        x = find_head(x);
        y = find_head(y);
        if (x == y) {
            return;
        }
        parent[x] = y;
        compSize[y] += compSize[x];
        pos[y] = merge(pos[y], pos[x]);
        connectedComponents--;
    }

    bool comp(int x, int y) {
        return (find_head(x) == find_head(y));
    }
};
int64_t dist (pair<pair<int64_t,int64_t>,int64_t> p1, pair<pair<int64_t,int64_t>,int64_t> p2) {
    int64_t d = abs(p1.first.first - p2.first.first) * abs(p1.first.first - p2.first.first);
    d += abs(p1.first.second - p2.first.second) * abs(p1.first.second - p2.first.second);
    return d;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int64_t N, K;
    cin >> N >> K;
    vector<pair<pair<int64_t,int64_t>,int64_t>> vec(N);
    vector<int64_t> v(N);
    for (int i = 0; i < N; i++) {
        cin >> vec[i].first.first >> vec[i].first.second;
        vec[i].second = i;
        cin >> v[i];
        v[i] %= K;
    }
    sort(vec.begin(), vec.end());
    DisjointSetUnion dsu(v, N, K);
    vector<pair<int,pair<int,int>>> edges;
    for (int64_t i = 0; i < N; i++) {
        for (int64_t j = max(i - 30, 0ll); j <= min(i + 30, N - 1); j++) {
            edges.push_back({dist(vec[i], vec[j]), {vec[i].second, vec[j].second}});
        }
    }
    for (int64_t i = 0; i < N; i++) {
        swap(vec[i].first.second, vec[i].first.first);
    }
    for (int64_t i = 0; i < N; i++) {
        for (int64_t j = max(i - 30, 0ll); j <= min(i + 30, N - 1); j++) {
            //cout << dist(vec[i], vec[j]) << " " << vec[i].second << " " << vec[j].second << '\n';
            edges.push_back({dist(vec[i], vec[j]), {vec[i].second, vec[j].second}});
        }
    }
    sort(edges.begin(), edges.end());
    for (auto& p: edges) {
        if (dsu.comp(p.second.first, p.second.second)) continue;
        lst = p.first;
        //cout << dist(vec[p.second.first])
        dsu.join(p.second.first, p.second.second);
    }
}

Compilation message

drzava.cpp:15: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   15 | #pragma GCC optimization ("O2")
      | 
drzava.cpp:16: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   16 | #pragma GCC optimization ("unroll-loops")
      | 
drzava.cpp: In member function 'std::vector<int> DisjointSetUnion::merge(std::vector<int>, std::vector<int>)':
drzava.cpp:37:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         for (int i = 0; i < a1.size(); i++) {
      |                         ~~^~~~~~~~~~~
drzava.cpp:38:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |             for (int j = 0; j < a2.size(); j++) {
      |                             ~~^~~~~~~~~~~
drzava.cpp: In function 'int main()':
drzava.cpp:109:41: error: no matching function for call to 'max(int64_t, long long int)'
  109 |         for (int64_t j = max(i - 30, 0ll); j <= min(i + 30, N - 1); j++) {
      |                                         ^
In file included from /usr/include/c++/10/vector:60,
                 from drzava.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
drzava.cpp:109:41: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
  109 |         for (int64_t j = max(i - 30, 0ll); j <= min(i + 30, N - 1); j++) {
      |                                         ^
In file included from /usr/include/c++/10/vector:60,
                 from drzava.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
drzava.cpp:109:41: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
  109 |         for (int64_t j = max(i - 30, 0ll); j <= min(i + 30, N - 1); j++) {
      |                                         ^
In file included from /usr/include/c++/10/algorithm:62,
                 from drzava.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
drzava.cpp:109:41: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
  109 |         for (int64_t j = max(i - 30, 0ll); j <= min(i + 30, N - 1); j++) {
      |                                         ^
In file included from /usr/include/c++/10/algorithm:62,
                 from drzava.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
drzava.cpp:109:41: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
  109 |         for (int64_t j = max(i - 30, 0ll); j <= min(i + 30, N - 1); j++) {
      |                                         ^
drzava.cpp:117:41: error: no matching function for call to 'max(int64_t, long long int)'
  117 |         for (int64_t j = max(i - 30, 0ll); j <= min(i + 30, N - 1); j++) {
      |                                         ^
In file included from /usr/include/c++/10/vector:60,
                 from drzava.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
drzava.cpp:117:41: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
  117 |         for (int64_t j = max(i - 30, 0ll); j <= min(i + 30, N - 1); j++) {
      |                                         ^
In file included from /usr/include/c++/10/vector:60,
                 from drzava.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
drzava.cpp:117:41: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
  117 |         for (int64_t j = max(i - 30, 0ll); j <= min(i + 30, N - 1); j++) {
      |                                         ^
In file included from /usr/include/c++/10/algorithm:62,
                 from drzava.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
drzava.cpp:117:41: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
  117 |         for (int64_t j = max(i - 30, 0ll); j <= min(i + 30, N - 1); j++) {
      |                                         ^
In file included from /usr/include/c++/10/algorithm:62,
                 from drzava.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
drzava.cpp:117:41: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
  117 |         for (int64_t j = max(i - 30, 0ll); j <= min(i + 30, N - 1); j++) {
      |                                         ^