Submission #1039444

# Submission time Handle Problem Language Result Execution time Memory
1039444 2024-07-30T21:50:12 Z Nika533 Drzava (COCI15_drzava) C++17
8 / 160
189 ms 6160 KB
#pragma GCC diagnostic warning "-std=c++11"
#include <bits/stdc++.h>
using namespace std;

const int N=50005,K=35;
int n,k,sz[N],p[N],val[N];
double x[N],y[N];

vector<pair<double,double>> point;

void make_set(int v) {
    p[v]=v; sz[v]=1;
}
int find_set(int v) {
    if (p[v]==v) return v;
    return p[v]=find_set(p[v]);
}
void merge_set(int a, int b) {
    a=find_set(a); b=find_set(b);
    if (a==b) return;
    if (sz[a]<sz[b]) swap(a,b);
    p[b]=a; sz[a]+=sz[b];
}
double dist(int a, int b) {
    return abs(x[a]-x[b])*abs(x[a]-x[b])+abs(y[a]-y[b])*abs(y[a]-y[b]);
}

bool solve(double d) {
    for (int i=1; i<=n; i++) make_set(i);
    set<pair<double,double>> cur;
    int l=1;
    for (int r=1; r<=n; r++) {
        int ind=point[r].second; cur.insert({y[ind],ind});
        while (l<r && point[r].first-d>point[l].first) {
            int indl=point[l].second; cur.erase({y[indl],indl}); l++;
        }
        auto it1=cur.lower_bound({y[ind]-d,0}),it2=cur.upper_bound({y[ind]+d,1e9});
        for (auto it=it1; it!=it2; it++) {
            int ind2=(*it).second;
            if (dist(ind,ind2)<=d*d) merge_set(ind,ind2);
            if (sz[find_set(ind)]>=k) return true;
        }
    }
    vector<bool> is_root(n+1,false);
    vector<int> comp[n+1];
    for (int i=1; i<=n; i++) {
        is_root[find_set(i)]=true; comp[find_set(i)].push_back(i);
    }
    for (int i=1; i<=n; i++) {
        if (!is_root[i]) continue;
        int s=comp[i].size();
        bool dp[s][k];
        for (int o=0; o<k; o++) dp[0][o]=false;
        dp[0][val[comp[i][0]]%k]=true;
        for (int j=1; j<s; j++) {
            for (int o=0; o<k; o++) {
                if (dp[j-1][o]) dp[j][(o+comp[i][j])%k]=true;
            }
        }
        if (dp[s-1][0]) return true;
    }
    return false;
}

int main() {
    cin>>n>>k; point.emplace_back(0,0);
    for (int i=1; i<=n; i++) {
        cin>>x[i]>>y[i]>>val[i]; point.emplace_back(x[i],i);
    }
    sort(point.begin(),point.end());
    double l=1,r=1e9,d=0;
    while (r-l>=0.00001) {
        double mid=(l+r)/2;
        if (solve(mid)) {
            r=mid-0.00001; d=mid;
        }
        else l=mid+0.00001;
    }
    cout<<fixed<<setprecision(3)<<d<<endl;
}

Compilation message

drzava.cpp:1:32: warning: '-std=c++11' is not an option that controls warnings [-Wpragmas]
    1 | #pragma GCC diagnostic warning "-std=c++11"
      |                                ^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 3 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 2 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 3 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 79 ms 3076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Incorrect 189 ms 6160 KB Output isn't correct
3 Halted 0 ms 0 KB -