提出 #3230608
ソースコード 拡げる
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
struct edge {
int from;
int to;
int cost;
edge(int _from, int _to, int _cost) : from(_from), to(_to), cost(_cost){};
};
vector<edge> ans;
// [add, add + L)のバイパスを作る
void bypass(int add, int L) {
// cout << L << ":" << add << endl;
if (L <= 0) return;
for (int k = 19; k >= 0; --k) {
if (L >= (1 << k)) {
// [add, add + 2^k)を作る
// k本の辺の後、つまり頂点k+1から20に辺を張る
ans.push_back(edge(k + 1, 20, add));
// [add + 2^k, add + L)を作る
bypass(add + (1 << k), L - (1 << k));
break;
}
}
return;
}
int main() {
int L;
cin >> L;
// 0の辺を全部張る
for (int i = 1; i < 20; ++i) {
ans.push_back(edge(i, i + 1, 0));
}
// 大まかにグラフを作る
for (int k = 19; k >= 1; --k) {
if (L >= (1 << k)) {
// k本辺を張って[0, 2^k)を作る
for (int i = 1; i <= k; ++i) {
ans.push_back(edge(i, i + 1, 1 << (i - 1)));
}
// [2^k, L)を作る
bypass(1 << k, L - (1 << k));
break;
}
}
cout << 20 << " " << ans.size() << endl;
for (auto e : ans) {
cout << e.from << " " << e.to << " " << e.cost << endl;
}
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | D - All Your Paths are Different Lengths |
| ユーザ | Tiramister |
| 言語 | C++14 (GCC 5.4.1) |
| 得点 | 700 |
| コード長 | 1508 Byte |
| 結果 | AC |
| 実行時間 | 1 ms |
| メモリ | 256 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 700 / 700 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | s1.txt, s2.txt |
| All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, s1.txt, s2.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 01.txt | AC | 1 ms | 256 KiB |
| 02.txt | AC | 1 ms | 256 KiB |
| 03.txt | AC | 1 ms | 256 KiB |
| 04.txt | AC | 1 ms | 256 KiB |
| 05.txt | AC | 1 ms | 256 KiB |
| 06.txt | AC | 1 ms | 256 KiB |
| 07.txt | AC | 1 ms | 256 KiB |
| 08.txt | AC | 1 ms | 256 KiB |
| 09.txt | AC | 1 ms | 256 KiB |
| 10.txt | AC | 1 ms | 256 KiB |
| 11.txt | AC | 1 ms | 256 KiB |
| 12.txt | AC | 1 ms | 256 KiB |
| 13.txt | AC | 1 ms | 256 KiB |
| 14.txt | AC | 1 ms | 256 KiB |
| 15.txt | AC | 1 ms | 256 KiB |
| 16.txt | AC | 1 ms | 256 KiB |
| 17.txt | AC | 1 ms | 256 KiB |
| 18.txt | AC | 1 ms | 256 KiB |
| 19.txt | AC | 1 ms | 256 KiB |
| 20.txt | AC | 1 ms | 256 KiB |
| s1.txt | AC | 1 ms | 256 KiB |
| s2.txt | AC | 1 ms | 256 KiB |