結果

問題 No.466 ジオラマ
ユーザー 🍡yurahuna🍡yurahuna
提出日時 2016-05-15 05:33:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,880 bytes
コンパイル時間 1,605 ms
コンパイル使用メモリ 169,992 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-08-17 06:55:00
合計ジャッジ時間 9,902 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 15 ms
4,376 KB
testcase_07 AC 10 ms
4,376 KB
testcase_08 AC 21 ms
4,380 KB
testcase_09 AC 13 ms
4,376 KB
testcase_10 AC 16 ms
4,380 KB
testcase_11 AC 12 ms
4,380 KB
testcase_12 AC 17 ms
4,380 KB
testcase_13 AC 9 ms
4,376 KB
testcase_14 AC 9 ms
4,376 KB
testcase_15 AC 12 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 9 ms
4,380 KB
testcase_18 AC 11 ms
4,376 KB
testcase_19 AC 12 ms
4,376 KB
testcase_20 AC 11 ms
4,376 KB
testcase_21 AC 11 ms
4,380 KB
testcase_22 AC 15 ms
4,380 KB
testcase_23 AC 11 ms
4,376 KB
testcase_24 AC 17 ms
4,380 KB
testcase_25 AC 19 ms
4,380 KB
testcase_26 AC 11 ms
4,376 KB
testcase_27 AC 20 ms
4,380 KB
testcase_28 AC 15 ms
4,380 KB
testcase_29 AC 19 ms
4,380 KB
testcase_30 AC 14 ms
4,380 KB
testcase_31 AC 14 ms
4,376 KB
testcase_32 AC 13 ms
4,380 KB
testcase_33 AC 11 ms
4,376 KB
testcase_34 AC 16 ms
4,376 KB
testcase_35 AC 13 ms
4,376 KB
testcase_36 AC 8 ms
4,376 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 10 ms
4,376 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 13 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 12 ms
4,380 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 10 ms
4,380 KB
testcase_45 AC 1 ms
4,376 KB
testcase_46 AC 6 ms
4,380 KB
testcase_47 AC 1 ms
4,376 KB
testcase_48 AC 14 ms
4,376 KB
testcase_49 AC 1 ms
4,376 KB
testcase_50 AC 13 ms
4,376 KB
testcase_51 AC 1 ms
4,376 KB
testcase_52 AC 12 ms
4,376 KB
testcase_53 AC 2 ms
4,376 KB
testcase_54 AC 11 ms
4,380 KB
testcase_55 AC 1 ms
4,376 KB
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 AC 15 ms
4,376 KB
testcase_67 AC 2 ms
4,380 KB
testcase_68 AC 13 ms
4,376 KB
testcase_69 AC 2 ms
4,376 KB
testcase_70 AC 9 ms
4,380 KB
testcase_71 AC 2 ms
4,376 KB
testcase_72 AC 8 ms
4,380 KB
testcase_73 AC 1 ms
4,500 KB
testcase_74 AC 13 ms
4,380 KB
testcase_75 AC 1 ms
4,380 KB
testcase_76 AC 2 ms
4,376 KB
testcase_77 AC 1 ms
4,376 KB
testcase_78 AC 2 ms
4,376 KB
testcase_79 AC 2 ms
4,376 KB
testcase_80 AC 1 ms
4,380 KB
testcase_81 AC 1 ms
4,380 KB
testcase_82 AC 1 ms
4,376 KB
testcase_83 AC 2 ms
4,376 KB
testcase_84 WA -
testcase_85 AC 29 ms
4,376 KB
testcase_86 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;

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

    int A, B, C, D;
    cin >> A >> B >> C >> D;

    int N = A + B - C;                  // 村の個数
    int M = (C == 0) ? N - 2 : N - 1;   // 辺の本数の最小値
    // 村が2個未満 or 辺の本数の最小値が Dより大きい ならば、条件を満たす組はない
    if (N < 2 || M > D) {
        cout << -1 << endl;
        return 0;
    }

    vector<P> edges;    // 水路を格納しておくやつ
    int id = 2; // 村0, 1の次の2から番号を振っていく
    // 村0からのみ水が流れる村は、村0を除くと A-C-1個
    rep(i, A - C - 1) {
        edges.emplace_back(P(0, id));
        id++;
    }
    // 村1からのみ水が流れる村は、村1を除くと B-C-1個
    rep(i, B - C - 1) {
        edges.emplace_back(P(1, id));
        id++;
    }

    // 村0と村1の両方から水が流れる村
    if (C > 0) {
        int par;
        if (C == A) {
            edges.emplace_back(P(1, 0));
            par = 0;
        }
        else if (C == B) {
            edges.emplace_back(P(0, 1));
            par = 1;
        }
        else {
            edges.emplace_back(P(0, id));
            edges.emplace_back(P(1, id));
            par = id;
        }
        rep2(i, id, N) {
            if (i == par) continue;
            edges.emplace_back(P(par, i));
        }
    }

    cout << N << " " << M << endl;
    assert(edges.size() == M);
    for (auto p : edges) {
        cout << p.first << " " << p.second << endl;
    }
}
0