結果
| 問題 |
No.466 ジオラマ
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2025-06-22 10:19:21 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,201 bytes |
| コンパイル時間 | 519 ms |
| コンパイル使用メモリ | 66,988 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-06-22 10:19:34 |
| 合計ジャッジ時間 | 10,970 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 3 |
| other | AC * 27 WA * 56 |
ソースコード
#include <iostream>
#include <vector>
using namespace std;
int main() {
int A, B, C, D;
cin >> A >> B >> C >> D;
// Calculate total number of villages
int N = A + B - C;
if (N < 2) {
cout << -1 << endl;
return 0;
}
// Check if C exceeds min(A, B)
if (C > min(A, B)) {
cout << -1 << endl;
return 0;
}
// Calculate minimum number of edges needed
int min_edges = (A - C) + (B - C) + (C > 0 ? C + 1 : 0);
if (min_edges > D) {
cout << -1 << endl;
return 0;
}
cout << N << " " << min_edges << endl;
int cnt = 1; // Start counting new villages from 2
// Villages only reachable from 0
for (int i = 0; i < A - C; ++i) {
cout << 0 << " " << ++cnt << endl;
}
// Villages only reachable from 1
for (int i = 0; i < B - C; ++i) {
cout << 1 << " " << ++cnt << endl;
}
// Common villages reachable from both 0 and 1
if (C > 0) {
int rt = ++cnt;
cout << 0 << " " << rt << endl;
cout << 1 << " " << rt << endl;
for (int i = 1; i < C; ++i) {
cout << rt << " " << ++cnt << endl;
}
}
return 0;
}
vjudge1