結果
問題 |
No.3134 二分探索木
|
ユーザー |
![]() |
提出日時 | 2025-05-05 00:20:30 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,381 bytes |
コンパイル時間 | 3,735 ms |
コンパイル使用メモリ | 284,196 KB |
実行使用メモリ | 18,176 KB |
最終ジャッジ日時 | 2025-05-05 00:20:38 |
合計ジャッジ時間 | 7,881 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 8 TLE * 1 -- * 6 |
ソースコード
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; struct Node { int val, depth, children; shared_ptr<Node> left, right; }; int main() { cin.tie(nullptr)->sync_with_stdio(false); int n; cin >> n; vector<int> a(n); rep(i, n) cin >> a[i]; vector<shared_ptr<Node>> nodes(n); shared_ptr<Node> root; root = make_shared<Node>(Node { a[0], 0, 0, nullptr, nullptr }); nodes[0] = root; for (int i = 1; i < n; ++i) { shared_ptr<Node> cur = root; while (true) { cur->children++; if (a[i] < cur->val) { if (cur->left == nullptr) { cur->left = make_shared<Node>(Node { a[i], cur->depth + 1, 0, nullptr, nullptr }); nodes[i] = cur->left; break; } else { cur = cur->left; } } else { if (cur->right == nullptr) { cur->right = make_shared<Node>(Node { a[i], cur->depth + 1, 0, nullptr, nullptr }); nodes[i] = cur->right; break; } else { cur = cur->right; } } } } rep(i, n) cout << nodes[i]->depth << ' '; cout << '\n'; rep(i, n) cout << nodes[i]->children << ' '; cout << '\n'; return 0; }