結果
| 問題 |
No.2597 Yet Another Topological Problem
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-11-22 01:03:35 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 30 ms / 2,000 ms |
| コード長 | 3,487 bytes |
| コンパイル時間 | 963 ms |
| コンパイル使用メモリ | 81,892 KB |
| 最終ジャッジ日時 | 2025-02-17 22:49:58 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 55 |
ソースコード
#include <algorithm>
#include <iostream>
#include <vector>
const std::string Possible{ "Possible" };
const std::string Impossible{ "Impossible" };
/**
* i(kp-1)
* : i(kp+1)
* : :
* +-------+ ......i
* | ..... |
* | : : |
* | : : |
* | : : |
* | : : |
* | : : +---- ......-R+i
* ---------+ : :.......
* ...........:
*/
void debug(const std::vector<std::pair<int, int>>& points) {
int maxx = 0;
int miny = 0, maxy = 0;
for (const auto& [x, y] : points) {
maxx = std::max(maxx, x);
miny = std::min(miny, y);
maxy = std::max(maxy, y);
}
std::vector<std::string> lines_(maxy - miny + 1, std::string(maxx + 1, ' '));
auto lines = lines_.rend() - (maxy + 1);
for (int x = 0; x <= maxx; ++x) {
lines[0][x] = '.';
}
lines[0][0] = '+';
for (size_t i = 1; i < points.size(); ++i) {
auto [px, py] = points[i - 1];
auto [cx, cy] = points[i];
if (i + 1 == points.size()) {
lines[cy][cx] = '+';
} else {
auto [nx, ny] = points[i + 1];
bool cv = px == cx;
bool nv = cx == nx;
if (cv != nv) {
lines[cy][cx] = '+';
} else if (cv) {
lines[cy][cx] = '|';
} else {
lines[cy][cx] = '-';
}
}
}
for (auto& line : lines_) {
std::cerr << line << '\n';
}
std::cerr.flush();
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int p, q;
std::cin >> p >> q;
if (p == 1) {
std::cout << Impossible << '\n';
return 0;
}
std::cout << Possible << '\n';
const int R = q / p;
// 拡大率 k (=D/q) が満たすべき条件:
// 1. R(kp+1)-R(kp-1) < kp R番目の山の幅が kp 未満
// 2. kq - R(kp-1) < kp R番目の山の左端と kq の距離が kp 未満
// 3. R(kp+1) <= kq R番目の山の右端より右側 (inclusive) に kq が存在
// それぞれ整理すると
// 1. k >= ceil((2R+1)/p)
// 2. k >= ceil((R+1)/(p(R+1)-q)
// 3. k >= ceil(R/(q-pR))
const int k = std::max({ 2 * R / p + 1, R / (p * (R + 1) - q) + 1, (R + q - p * R - 1) / (q - p * R) });
std::vector<std::pair<int, int>> points;
for (int i = 0; i < R; ++i) {
int x = i * (k * p + 1);
int y = i;
// R
while (y > -R + i) {
points.emplace_back(x, y);
--y;
}
while (x < (i + 1) * (k * p - 1)) {
points.emplace_back(x, y);
++x;
}
// R + 1
while (y < i + 1) {
points.emplace_back(x, y);
++y;
}
while (x < (i + 1) * (k * p + 1)) {
points.emplace_back(x, y);
++x;
}
}
int x = R * (k * p + 1);
int y = R;
// R
while (y > 0) {
points.emplace_back(x, y);
--y;
}
while (x <= k * q) {
points.emplace_back(x, y);
++x;
}
// x 方向の長さの和 = kq <= 125000 where R<=249,2<=p<q<=500
// y 方向の長さの和 = R(2R+2) <= 124500 where R<=249
// 長さの和 <= 249500
std::cout << points.size() - 1 << '\n';
for (const auto& [x, y] : points) {
std::cout << x << ' ' << y << '\n';
}
// debug(points);
}