結果

問題 No.466 ジオラマ
ユーザー nebukuro09
提出日時 2016-12-16 14:53:18
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 1,406 bytes
コンパイル時間 818 ms
コンパイル使用メモリ 111,992 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-12 05:39:12
合計ジャッジ時間 4,400 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 83
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;


void w(int a, int b) {writeln(a, " ", b);}

void main() {
  int A, B, C, D;
  scanf("%d %d %d %d", &A, &B, &C, &D);

  if (A == C && B == C) {
    if (C == 1 || D < C) {writeln(-1); return;}
    w(C, C);
    w(0, 1);
    w(1, 0);
    foreach (i; 2..C)
      w(0, i);
  }
  
  else if (A == C) {
    if (D < B-1) {writeln(-1); return;}
    w(B, B-1);
    foreach (i; 2..A+1)
      w(0, i);
    w(1, 0);
    foreach (i; 0..B-A-1)
      w(1, A+1+i);
  }
  
  else if (B == C) {
    if (D < A-1) {writeln(-1); return;}
    w(A, A-1);
    foreach (i; 2..B+1)
      w(1, i);
    w(0, 1);
    foreach (i; 0..A-B-1)
      w(0, B+1+i);
  }
  
  else {
    int nodes = A + B - C;
    int edges = (A - C - 1) + (B - C - 1) + (C > 0 ? C + 1 : 0);
    if (D < edges) {writeln(-1); return;}

    w(nodes, edges);
    int n = 1;
    if (C > 0) {
      w(0, 2);
      w(1, 2);
      n++;
      foreach (i; 0..C-1) {
        w(n, n+1);
        n++;
      }
    }

    if (A - C - 1 > 0) {
      n++;
      w(0, n);
      foreach (i; 0..A-C-2) {
        w(n, n+1);
        n++;
      }
    }

    if (B - C - 1 > 0) {
      n++;
      w(1, n);
      foreach (i; 0..B-C-2) {
        w(n, n+1);
        n++;
      }
    }
  }
}
0