| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 891636 | boris_mihov | 함박 스테이크 (JOI20_hamburg) | C++17 | 1117 ms | 1048576 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
#include <random>
#include <chrono>
#include <stack>
#include <queue>
typedef long long llong;
const int MAXN = 200000 + 10;
const int INF = 1e9;
struct Point
{
int x, y;
};
struct Rectangle
{
Point down, up;
bool intersectWith(Rectangle b)
{
if (std::max(down.x, b.down.x) > std::min(up.x, b.up.x)) return false;
if (std::max(down.y, b.down.y) > std::min(up.y, b.up.y)) return false;
return true;
}
Rectangle intersectionWith(Rectangle b)
{
Rectangle result;
result.down.x = std::max(down.x, b.down.x);
result.down.y = std::max(down.y, b.down.y);
result.up.x = std::min(up.x, b.up.x);
result.up.y = std::min(up.y, b.up.y);
return result;
}
};
int n, k;
Rectangle rects[MAXN];
std::vector <Point> solution;
std::vector <Rectangle> rec(std::vector <Rectangle> &curr)
{
if (curr.size() == 1)
{
return curr;
}
std::vector <std::vector <Rectangle>> split;
for (const Rectangle &currRect : curr)
{
bool found = false;
for (int i = 0 ; i < split.size() ; ++i)
{
if (split[i][0].intersectWith(currRect))
{
found = true;
split[i].push_back(currRect);
}
}
if (!found)
{
split.push_back({currRect});
continue;
}
}
if (split.size() == 1)
{
Rectangle begin = split[0][0];
split[0].erase(split[0].begin());
std::vector <Rectangle> sol = rec(split[0]);
for (int i = 0 ; i < sol.size() ; ++i)
{
assert(sol[i].intersectWith(begin));
sol[i] = sol[i].intersectionWith(begin);
}
return sol;
}
std::vector <Rectangle> sol;
for (std::vector <Rectangle> &currSplit : split)
{
std::vector <Rectangle> res = rec(currSplit);
for (const Rectangle &r : res)
{
sol.push_back(r);
}
}
return sol;
}
std::mt19937 rng(69420); //std::chrono::steady_clock::now().time_since_epoch().count());
void solve()
{
std::vector <Rectangle> solveFor;
for (int i = 1 ; i <= n ; ++i)
{
solveFor.push_back(rects[i]);
}
std::shuffle(solveFor.begin(), solveFor.end(), rng);
std::vector <Rectangle> mySol = rec(solveFor);
for (int i = 0 ; i < mySol.size() ; ++i)
{
solution.push_back(mySol[i].down);
}
assert(1 <= solution.size() && solution.size() <= k);
while (solution.size() < k) solution.push_back(solution.back());
for (const Point &curr : solution)
{
std::cout << curr.x << ' ' << curr.y << '\n';
}
}
void input()
{
std::cin >> n >> k;
for (int i = 1 ; i <= n ; ++i)
{
std::cin >> rects[i].down.x >> rects[i].down.y >> rects[i].up.x >> rects[i].up.y;
if (rects[i].down.x > rects[i].up.x) std::swap(rects[i].down.x, rects[i].up.x);
if (rects[i].down.y > rects[i].up.y) std::swap(rects[i].down.y, rects[i].up.y);
}
}
void fastIOI()
{
std::ios_base :: sync_with_stdio(0);
std::cout.tie(nullptr);
std::cin.tie(nullptr);
}
int main()
{
fastIOI();
input();
solve();
return 0;
}컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
