結果

問題 No.1981 [Cherry 4th Tune N] アルゴリズムが破滅する例
ユーザー legosukelegosuke
提出日時 2022-06-17 22:27:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,593 bytes
コンパイル時間 2,328 ms
コンパイル使用メモリ 197,980 KB
実行使用メモリ 6,816 KB
最終ジャッジ日時 2024-04-17 14:38:01
合計ジャッジ時間 5,258 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

void ng() {
    cout << -1 << endl;
    exit(EXIT_SUCCESS);
}

using P = pair<int, int>;

int main() {
    int N, K;
    cin >> N >> K;
    if (K == 0) {
        ng();
    }
    int n = -1;
    vector<P> es;
    if (N % 2 == 0) {
        n = N / 2;
        if (K < n) {
            ng();
        }
        for (int i = 0; i < n; ++i) {
            int v = 2 * i, u = v + 1;
            if (K >= 2) {
                es.emplace_back(v, v);
                es.emplace_back(u, u);
                K -= 2;
            } else {
                es.emplace_back(u, v);
                K -= 1;
            }
        }
        if (K > 0) {
            ng();
        }
    } else {
        n = (N - 3) / 2;
        if (K < n + 2) {
            ng();
        }
        for (int i = 0; i < n; ++i) {
            int u = 2 * i, v = u + 1;
            if (K >= 2) {
                es.emplace_back(u, u);
                es.emplace_back(v, v);
                K -= 2;
            } else {
                es.emplace_back(u, v);
                K -= 1;
            }
        }
        int u = 2 * n, v = u + 1, w = v + 1;
        if (K <= 1) {
            ng();
        } else if (K == 2) {
            es.emplace_back(u, v);
            es.emplace_back(v, w);
        } else if (K == 3) {
            es.emplace_back(u, u);
            es.emplace_back(v, v);
            es.emplace_back(w, w);
        } else {
            ng();
        }
    }
    cout << es.size() << endl;
    for (auto [u, v] : es) {
        cout << u + 1 << " " << v + 1 << endl;
    }
}
0