Submission #60975553
Source Code Expand
Copy
#include <iostream>#include <vector>#include <algorithm>#include <iomanip>using namespace std;struct Building {long long x, h;};// ビルが見えるかどうかを判定bool canSeeAllBuildings(const vector<Building>& buildings, double height) {double maxSlope = -1e18; // 現時点での最大傾きfor (const auto& building : buildings) {double slope = (building.h - height) / building.x;if (slope <= maxSlope) {return false; // 現在のビルが他のビルに遮られる}maxSlope = max(maxSlope, slope);}return true;
#include <iostream> #include <vector> #include <algorithm> #include <iomanip> using namespace std; struct Building { long long x, h; }; // ビルが見えるかどうかを判定 bool canSeeAllBuildings(const vector<Building>& buildings, double height) { double maxSlope = -1e18; // 現時点での最大傾き for (const auto& building : buildings) { double slope = (building.h - height) / building.x; if (slope <= maxSlope) { return false; // 現在のビルが他のビルに遮られる } maxSlope = max(maxSlope, slope); } return true; } int main() { int n; cin >> n; vector<Building> buildings(n); for (int i = 0; i < n; ++i) { cin >> buildings[i].x >> buildings[i].h; } // 高さを二分探索 double low = 0.0, high = 1e9, result = -1.0; const double eps = 1e-9; while (high - low > eps) { double mid = (low + high) / 2.0; if (canSeeAllBuildings(buildings, mid)) { high = mid; // 高さを下げられる result = mid; } else { low = mid; // 高さを上げる必要がある } } if (canSeeAllBuildings(buildings, 0.0)) { cout << -1 << endl; // 高さ 0 で全てのビルが見える場合 } else { cout << fixed << setprecision(18) << result << endl; } return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Visible Buildings |
User | VIP1109 |
Language | C++ 20 (gcc 12.2) |
Score | 0 |
Code Size | 1454 Byte |
Status | WA |
Exec Time | 2207 ms |
Memory | 6308 KiB |
Judge Result
Set Name | Sample | All | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 525 | ||||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt |
All | hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
hand_01.txt | WA | 1 ms | 3560 KiB |
hand_02.txt | AC | 1 ms | 3432 KiB |
hand_03.txt | WA | 1 ms | 3680 KiB |
hand_04.txt | AC | 1 ms | 3488 KiB |
random_01.txt | WA | 97 ms | 6308 KiB |
random_02.txt | WA | 72 ms | 5540 KiB |
random_03.txt | WA | 62 ms | 5316 KiB |
random_04.txt | WA | 32 ms | 4160 KiB |
random_05.txt | WA | 71 ms | 5500 KiB |
random_06.txt | WA | 36 ms | 4156 KiB |
random_07.txt | WA | 13 ms | 3860 KiB |
random_08.txt | WA | 49 ms | 4752 KiB |
random_09.txt | WA | 7 ms | 3688 KiB |
random_10.txt | WA | 21 ms | 3924 KiB |
random_11.txt | WA | 62 ms | 5212 KiB |
random_12.txt | WA | 44 ms | 4584 KiB |
random_13.txt | WA | 12 ms | 3856 KiB |
random_14.txt | WA | 24 ms | 3900 KiB |
random_15.txt | WA | 86 ms | 5480 KiB |
random_16.txt | AC | 70 ms | 5372 KiB |
random_17.txt | AC | 51 ms | 4776 KiB |
random_18.txt | WA | 70 ms | 5476 KiB |
random_19.txt | TLE | 2207 ms | 5072 KiB |
sample_01.txt | AC | 1 ms | 3760 KiB |
sample_02.txt | AC | 1 ms | 3572 KiB |
sample_03.txt | AC | 1 ms | 3560 KiB |
sample_04.txt | AC | 1 ms | 3860 KiB |