답안 #542565

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
542565 2022-03-26T23:08:35 Z Olympia Drzava (COCI15_drzava) C++17
0 / 160
928 ms 34880 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;
int64_t lst = 0;
class DisjointSetUnion {
protected:
    vector<int> parent;
    int k;
    vector<int> pos;
    int n;
    int connectedComponents;
public:
    int getConnectedComponents() const {
        return connectedComponents;
    }

public:
    int merge (int x, int y) {
        for (int i = 0; i < k; i++) {
            if ((x & (1 << i)) && (y & (1 << (k - i)))) {
                cout << fixed << setprecision(3) << sqrt(lst) << '\n';
                exit(0);
            }
        }
        int ans = 0;
        for (int i = 0; i < k; i++) {
            for (int j = 0; j < k; j++) {
                if (ans & (1 << (i + j) % k)) {
                    continue;
                }
                if ((x & (1 << i)) && (y & (1 << j))) {
                    ans += (1 << (i + j) % k);
                }
            }
        }
        return ans;
    }
    DisjointSetUnion(vector<int> arr, int sz, int K) {
        n = sz;
        parent.resize(sz);
        for (int i = 0; i < n; i++) {
            parent[i] = i;
        }
        this->k = K;
        pos.resize(sz);
        for (int i = 0; i < sz; i++) {
            pos[i] = (1 << arr[i]) + 1;
        }
    }

    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;
        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;
}

vector<pair<pair<int,int>,int>> vec;

bool cmp (pair<int,int> p1, pair<int,int> p2) {
    return dist(vec[p1.first], vec[p1.second]) < dist(vec[p2.first], vec[p2.second]);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, K;
    cin >> N >> K;
    vec.resize(N);
    vector<int> dum(N);
    for (int i = 0; i < N; i++) {
        cin >> vec[i].first.first >> vec[i].first.second;
        vec[i].second = i;
        cin >> dum[i];
    }
    sort(vec.begin(), vec.end());
    vector<pair<int,int>> edges;
    for (int i = 0; i < N; i++) {
        for (int j = max(i - K, 0); j <= min(i + K, N - 1); j++) {
            //cout << i << " " << j << '\n';
            edges.push_back({i, j});
        }
    }
    vector<int> v(N);
    for (int i = 0; i < vec.size(); i++) {
        v[vec[i].second] = dum[i];
    }
    DisjointSetUnion dsu(v, N, K);
    sort(edges.begin(), edges.end(), cmp);
    for (auto& p: edges) {
        if (dsu.comp(p.first, p.second)) continue;
        lst = dist(vec[p.first], vec[p.second]);
        dsu.join(p.second, p.first);
    }
}

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 function 'int main()':
drzava.cpp:122:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  122 |     for (int i = 0; i < vec.size(); i++) {
      |                     ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 8 ms 984 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 928 ms 34092 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 690 ms 34880 KB Output isn't correct
3 Halted 0 ms 0 KB -