31692023-02-21 12:32:03rennHírvivők csoportosítása (40)cpp17Wrong answer 21/4014ms6136 KiB
#include <bits/stdc++.h>
using namespace std;

#define GOTTAGOFAST cin.tie(0); ios::sync_with_stdio(0);

int cnt;
void bfs(int c, int &n, int &cl, int &k, vector<bool> &volt, vector<pair<int, int>> &pontok);

bool megold(int n, int cl, int &k, vector<bool> &volt, vector<pair<int, int>> &pontok)
{
    fill(volt.begin(), volt.end(), false);
    
    cnt = 0;

    for (int i = 0; i < n; i++)
    {
        if(volt[i]) continue;
        cnt++;
        bfs(i, n, cl, k, volt, pontok);
    }

    return cnt <= k;
}

void bfs(int c, int &n, int &cl, int &k, vector<bool> &volt, vector<pair<int, int>> &pontok)
{
    volt[c] = true;
    for(int i = 0; i < n; i++)
    {
        if(volt[i]) continue;
        if(abs(pontok.at(c).first-pontok.at(i).first)+abs(pontok.at(c).second-pontok.at(i).second) <= cl)
        {
            bfs(i, n, cl, k, volt, pontok);
            continue;
        }
    }
}

int main()
{

    GOTTAGOFAST

    int x, y, n, k;
    cin >> x >> y >> n >> k;

    vector<vector<int>> graf(n, vector<int>(n, -1));
    vector<pair<int, int>> pontok(n);
    vector<bool> volt(n);
    int a, b;
    for (size_t i = 0; i < n; i++)
    {
        cin >> a >> b;
        pontok.at(i) = {a, b};
    }

    int left = 0, right = 1000001, mid;
    //cout << "----\n";
    while(left <= right)
    {
        
        mid = left+(right-left)/2;
        //cout << left << " " << mid << " " << right << "\n";

        if(megold(n, mid, k, volt, pontok))
        {
            right = mid-1;
        }
        else
        {
            left = mid+1;
        }
    }

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

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base21/40
1Accepted0/03ms1828 KiB
2Accepted0/013ms3516 KiB
3Accepted1/13ms2440 KiB
4Wrong answer0/13ms2360 KiB
5Wrong answer0/14ms3004 KiB
6Accepted1/14ms2992 KiB
7Accepted1/13ms2656 KiB
8Accepted1/13ms2928 KiB
9Accepted1/13ms2880 KiB
10Accepted1/14ms3188 KiB
11Wrong answer0/14ms3236 KiB
12Wrong answer0/14ms3412 KiB
13Wrong answer0/314ms4912 KiB
14Wrong answer0/314ms5128 KiB
15Accepted3/314ms5480 KiB
16Wrong answer0/314ms5804 KiB
17Accepted3/314ms5528 KiB
18Wrong answer0/314ms5524 KiB
19Wrong answer0/314ms5708 KiB
20Accepted3/314ms5916 KiB
21Accepted3/314ms6136 KiB
22Accepted3/314ms6072 KiB