제출 #234671

#제출 시각아이디문제언어결과실행 시간메모리
234671AlexLuchianov함박 스테이크 (JOI20_hamburg)C++14
21 / 100
3081 ms3636 KiB
#include <iostream>
#include <vector>
#include <cmath>
#include <cassert>
#include <random>
#include <algorithm>

using namespace std;

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 200000;
int const inf = 1000000000;

int const sigma = 4;

class Rect{
public:
  int x;
  int y;
  int x2;
  int y2;
  Rect operator + (Rect a) {
    return {max(x, a.x), max(y, a.y), min(x2, a.x2), min(y2, a.y2)};
  }
  bool valid(){
    return (x <= x2) && (y <= y2);
  }
  ll area(){
    return 1LL * (x2 - x + 1) * (y2 - y + 1);
  }
} v[1 + nmax];
mt19937 rng;

int solve(int n, int k){
  shuffle(v + 1, v + n + 1, rng);
  Rect base[1 + sigma];
  for(int i = 1; i <= k; i++)
    base[i] = {1, 1, inf, inf};

  for(int i = 1;i <= n; i++){
    ll smin = 1LL * inf * inf;
    for(int j = 1;j <= k; j++)
      if((base[j] + v[i]).valid())
        smin = min(smin, base[j].area() - (base[j] + v[i]).area());
    if(smin == 1LL * inf * inf)
      return 0;

    for(int j = 1;j <= k; j++)
      if((base[j] + v[i]).valid() && base[j].area() - (base[j] + v[i]).area() == smin) {
         base[j] = base[j] + v[i];
         break;
      }
  }

  for(int j = 1;j <= k; j++)
    cout << base[j].x << " " << base[j].y << '\n';
  return 1;
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);

  int n, k;
  cin >> n >> k;
  for(int i = 1;i <= n; i++)
    cin >> v[i].x >> v[i].y >> v[i].x2 >> v[i].y2;
  while(solve(n, k) == 0);
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...