Submission #527813

# Submission time Handle Problem Language Result Execution time Memory
527813 2022-02-18T11:58:38 Z colazcy Drzava (COCI15_drzava) C++11
0 / 160
3 ms 648 KB
#include <iostream>
#include <cmath>
#include <cassert>
#include <set>
#include <algorithm>
#define let const auto
#define rep(name,beg,end) for(auto lim_##name = end,name = beg;name <= lim_##name;name++)
#define per(name,beg,end) for(auto lim_##name = end,name = beg;name >= lim_##name;name--)
#define repn(lim) for(auto REPN_LIM = lim,REPN = 1;REPN <= REPN_LIM;REPN++)
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define trace() debug("Line : %d, Function : %s\n",__LINE__,__FUNCTION__)
using ll = long long;
constexpr int maxn = 5e4 + 10;
constexpr ll sq(const ll x){return x * x;}


int n,k,v[maxn],now[maxn];
namespace dsu{
	int f[maxn];
	void init(){rep(i,1,n)f[i] = i;}
	int find(const int x){return x == f[x] ? x : f[x] = find(f[x]);}
	void merge(const int x,const int y){f[find(x)] = find(y);}
}
struct Point{
	int x,y,id;
}val[maxn];

bool chk(const ll lim){
	dsu::init();
	let cmp = [](const Point &a,const Point &b){
		if(a.y != b.y)return a.y < b.y;
		return a.x < b.x;
	};
	std::multiset<Point,decltype(cmp)> s(cmp);
	for(int l = 1,r = 1;r <= n;r++){
		s.insert(val[r]);
		while(sq(val[r].x - val[l].x) > lim)s.erase(val[l++]);

		auto itl = s.lower_bound(val[r]),itr = s.lower_bound(val[r]);
		while(itr != s.end() && sq(val[r].y - itr->y) <= lim)itr++;
		while(itl != s.begin() && sq(val[r].y - std::prev(itl)->y) <= lim)itl--;
		s.erase(s.begin(),itl);
		s.erase(itr,s.end());
		
		if((int)s.size() > 8 * k)return true;
		for(let x : s){
			if(sq(x.x - val[r].x) + sq(x.y - val[r].y) <= lim)
			dsu::merge(val[r].id,x.id);
		}
	}
	std::fill(now + 1,now + 1 + n,0);
	rep(i,1,n){
		let f = dsu::find(i);
		ll tmp = (now[f] << v[i]);
		tmp |= (tmp >> k);
		tmp &= (1 << k) - 1;
		now[f] |= tmp;
		now[f] |= 1 << v[i];
		if(now[f] & 1)return true;
	}
	return false;
}	
int main(){
#ifndef ONLINE_JUDGE
	std::freopen("fufu.in","r",stdin);
#endif
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cin >> n >> k;
	rep(i,1,n)std::cin >> val[i].x >> val[i].y >> v[i],val[i].id = i;
	std::sort(val + 1,val + 1 + n,[](const Point &a,const Point &b){
		if(a.x != b.x)return a.x < b.x;
		return a.y < b.y;
	});
	ll l = 0,r = 1e16,ans = -1;
	while(l <= r){
		let mid = (l + r) >> 1;
		if(chk(mid))ans = mid,r = mid - 1;
		else l = mid + 1;
	}
	assert(ans != -1);
	std::printf("%.3lf\n",double(std::sqrt(ans)));	
	return 0;
}

Compilation message

drzava.cpp: In function 'int main()':
drzava.cpp:65:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |  std::freopen("fufu.in","r",stdin);
      |  ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 568 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 592 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 648 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 592 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 592 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 592 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 592 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 592 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 592 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 592 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 592 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 592 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 592 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 592 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 592 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 592 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 592 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 592 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 592 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 592 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -