답안 #715322

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
715322 2023-03-26T13:00:36 Z Volkos 함박 스테이크 (JOI20_hamburg) C++14
0 / 100
3000 ms 340 KB
#include <bits/stdc++.h>
#pragma GCC target ("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll long long
#define ld long double
#define endl '\n'
#define S second
#define F first
#define pb push_back
#define mp make_pair
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
using namespace std;
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;

const ll maxn = 2e5+50;
ll n, k;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

struct rect{
	int x1, y1, x2, y2;
}a[maxn], b[maxn];

rect intersect(rect a, rect b){
	rect res;
	res.x1 = max(a.x1, b.x1);
	res.y1 = max(a.y1, b.y1);
	res.x2 = min(a.x2, b.x2);
	res.y2 = min(a.y2, b.y2);
	return res;
}

ld area(rect a){
	if(a.x1 > a.x2 || a.y1 > a.y2) return 0;
	return 1.0 * (a.y2 - a.y1 + 1) * (a.x2 - a.x1 + 1);
}

ld calc(rect a, rect b){
	rect tmp = intersect(a, b);
	return (ld)area(tmp) / area(a);
}


int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    srand(time(NULL));
	cin>>n>>k;
	for(ll i=0; i<n-3; i++){
		//cin>>a[i].x1>>a[i].y1>>a[i].x2>>a[i].y2;
		a[i].x1 = a[i].y1 = a[i].x2 = a[i].y2 = 1;
	}

	for(ll i=n-3; i<n; i++){
		a[i].x1 = a[i].y1 = a[i].x2 = a[i].y2 = i;
	}

	while(true){
		bool flag = 1;
		shuffle(a, a+n, rng);
		for(ll i=0; i<k; i++){
			b[i] = a[i];
		}

		for(ll i=k; i<n; i++){
			ll curr = 0;
			ld mxar = -1;
			for(ll j = 0; j<k; j++){
				ld t = calc(b[j], a[i]);
				if(t > mxar){
					mxar = t, curr = j;
				}
			}

			b[curr] = intersect(b[curr], a[i]);
			if(area(b[curr]) == 0){
				flag = 0;
				break;
			}
		}

		if(flag){
			cout<<k<<endl;
			for(ll i=0; i<k; i++){
				cout<<b[i].x1<<" "<<b[i].y1<<endl;
			}
			break;
		}
	}

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3018 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3032 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3044 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3052 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3018 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3032 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3044 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3052 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -