結果

問題 No.466 ジオラマ
ユーザー tubo28tubo28
提出日時 2016-12-16 03:27:54
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,251 bytes
コンパイル時間 1,906 ms
コンパイル使用メモリ 181,676 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-30 10:08:41
合計ジャッジ時間 7,394 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 70 WA * 12 RE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << x << endl

set<pair<int,int>> es;

bool solve(int a, int b, int c, int m){
    int n = a + b + c;
    int k = 2;
    es.clear();
    vector<int> as, bs, cs;

    rep(i, a - 1) as.push_back(k++);
    rep(i, b - 1) bs.push_back(k++);

    if(!c){
        if(!a || !b) return false;
        as.push_back(0);
        bs.push_back(1);
    } else {
        if(a) as.push_back(0); else cs.push_back(0);
        if(b) bs.push_back(1); else cs.push_back(1);
        rep(i, c - !a - !b) cs.push_back(k++);
    }

    sort(all(as));
    sort(all(bs));
    sort(all(cs));

    dump(a);
    dump(b);
    dump(c);

    // for(auto &e : as) cout << e << ' ';
    // cout << endl;
    // for(auto &e : bs) cout << e << ' ';
    // cout << endl;
    // for(auto &e : cs) cout << e << ' ';
    // cout << endl;

    assert((int)as.size() == a);
    assert((int)bs.size() == b);
    assert((int)cs.size() == c);
    assert(k == n);

    rep(i, a - 1) es.emplace(as[i], as[i+1]), --m;
    rep(i, b - 1) es.emplace(bs[i], bs[i+1]), --m;
    rep(i, c - 1) es.emplace(cs[i], cs[i+1]), --m;
    if(a && c) es.emplace(as[0], cs[0]), --m;
    if(b && c) es.emplace(bs[0], cs[0]), --m;

    return m >= 0;

    // auto fill_v = [&](const vector<int> &vs){
    //     rep(i, vs.size()) rep(j, i){
    //         if(m && !g[vs[i]][vs[j]]) g[vs[i]][vs[j]] = true, --m;
    //     }
    // };
    // auto fill_vw = [&](const vector<int> &vs, const vector<int> &ws){
    //     rep(i, vs.size()) rep(j, ws.size()){
    //         if(m && !g[vs[i]][ws[j]]) g[vs[i]][ws[j]] = true, --m;
    //     }
    // };

    // fill_v(as);
    // fill_v(bs);
    // fill_v(cs);
    // fill_vw(as, cs);
    // fill_vw(bs, cs);
}

int main(){
    int A, B, C, D;
    while(cin >> A >> B >> C >> D){
        int a = A - C;
        int b = B - C;
        if(solve(a, b, C, D)){
            int n = a + b + C;
            int m = es.size();
            cout << n << ' ' << m << '\n';
            for(auto &e : es) cout << e.first << ' ' << e.second << '\n';
        } else puts("-1");
    }
}
0