結果

問題 No.2597 Yet Another Topological Problem
ユーザー suisensuisen
提出日時 2023-11-21 23:49:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,916 bytes
コンパイル時間 697 ms
コンパイル使用メモリ 76,472 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-24 23:30:26
合計ジャッジ時間 6,929 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 WA -
testcase_06 AC 2 ms
6,676 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
6,676 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 2 ms
6,676 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2 ms
6,676 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 2 ms
6,676 KB
testcase_28 AC 2 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 2 ms
6,676 KB
testcase_31 AC 2 ms
6,676 KB
testcase_32 AC 2 ms
6,676 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

const std::string Possible{"Possible"};
const std::string Impossible{"Impossible"};

/**
 *       i(kp-1)
 *          :    i(kp+1)
 *          :       :
 *          +-------+       ......i
 *          | ..... |
 *          | :   : |
 *          | :   : |
 *          | :   : |
 *          | :   : |
 *          | :   : +----   ......-R+i
 * ---------+ :   :.......
 * ...........:
 */

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 が満たすべき条件: (R-1)(kp+1) <= R(kp-1)
    // k=ceil(2R/(p+1)) で十分

    const int k = (2 * R + p) / (p + 1);

    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      <= 83500  where R<=250,2<=p<q<=500
    // y 方向の長さの和 = R(2R+2) <= 125500 where R<=250
    // 長さの和 <= 209000

    std::cout << points.size() << '\n';
    for (const auto &[x, y] : points) {
        std::cout << x << ' ' << y << '\n';
    }
}
0