提出 #60980021
ソースコード 拡げる
// https://atcoder.jp/contests/abc385/tasks/abc385_f
pub mod solution {
//{"name":"F - Visible Buildings","group":"AtCoder - UNIQUE VISION Programming Contest 2024 Christmas (AtCoder Beginner Contest 385)","url":"https://atcoder.jp/contests/abc385/tasks/abc385_f","interactive":false,"timeLimit":2000,"tests":[{"input":"3\n3 2\n5 4\n7 5\n","output":"1.500000000000000000\n"},{"input":"2\n1 1\n2 100\n","output":"-1\n"},{"input":"3\n1 1\n2 2\n3 3\n","output":"0.000000000000000000\n"},{"input":"4\n10 10\n17 5\n20 100\n27 270\n","output":"17.142857142857142350\n"}],"testType":"single","input":{"type":"stdin","fileName":null,"pattern":null},"output":{"type":"stdout","fileName":null,"pattern":null},"languages":{"java":{"taskClass":"FVisibleBuildings"}}}
use crate::algo_lib::collections::iter_ext::collect::IterCollect;
use crate::algo_lib::io::input::Input;
use crate::algo_lib::io::output::Output;
type PreCalc = ();
fn check(height: f64, buildings: &[(usize, usize)]) -> bool {
let mut max_slope = f64::NEG_INFINITY;
for &(x, h) in buildings {
let (x, h) = (x as f64, h as f64);
let slope = (h - height) / x;
if slope <= max_slope {
return false;
}
max_slope = slope;
}
true
}
fn solve(input: &mut Input, out: &mut Output, _test_case: usize, _data: &PreCalc) {
let n = input.read_size();
let buildings = (0..n)
.map(|_| (input.read_size(), input.read_size()))
.collect_vec();
// first we need to check if we can see all building from 0
if buildings.windows(2).all(|w| {
let (x1, h1) = w[0];
let (x2, h2) = w[1];
h1 * x2 < h2 * x1
}) {
out.print_line(-1);
return;
}
let mut l: f64 = 0.0;
let mut r: f64 = 1e32;
while r - l > 1e-14 {
let mid = (l + r) / 2.0;
if check(mid, &buildings) {
r = mid;
} else {
l = mid;
}
// out.print_line(format!("{} {}", l, r));
}
out.print_line(format!("{:.15}", r));
}
pub(crate) fn run(mut input: Input, mut output: Output) -> bool {
let pre_calc = ();
#[allow(dead_code)]
enum TestType {
Single,
MultiNumber,
MultiEof,
}
let test_type = TestType::Single;
match test_type {
TestType::Single => solve(&mut input, &mut output, 1, &pre_calc),
TestType::MultiNumber => {
let t = input.read();
for i in 0usize..t {
solve(&mut input, &mut output, i + 1, &pre_calc);
}
}
TestType::MultiEof => {
let mut i = 1;
while input.peek().is_some() {
solve(&mut input, &mut output, i, &pre_calc);
i += 1;
}
}
}
output.flush();
input.skip_whitespace();
input.peek().is_none()
}
}
pub mod algo_lib {
pub mod collections {
pub mod iter_ext {
pub mod collect {
pub trait IterCollect<T>: Iterator<Item = T> + Sized {
fn collect_vec(self) -> Vec<T> {
self.collect()
}
}
impl<T, I: Iterator<Item = T> + Sized> IterCollect<T> for I {}
}
}
}
pub mod io {
pub mod input {
use std::fmt::Debug;
use std::io::Read;
use std::str::FromStr;
pub struct Input<'s> {
input: &'s mut dyn Read,
buf: Vec<u8>,
at: usize,
buf_read: usize,
}
macro_rules! read_impl {
($t: ty, $read_name: ident, $read_vec_name: ident) => {
pub fn $read_name(&mut self) -> $t {
self.read()
}
pub fn $read_vec_name(&mut self, len: usize) -> Vec<$t> {
self.read_vec(len)
}
};
($t: ty, $read_name: ident, $read_vec_name: ident, $read_pair_vec_name: ident) => {
read_impl!($t, $read_name, $read_vec_name);
pub fn $read_pair_vec_name(&mut self, len: usize) -> Vec<($t, $t)> {
self.read_vec(len)
}
};
}
impl<'s> Input<'s> {
const DEFAULT_BUF_SIZE: usize = 4096;
pub fn new(input: &'s mut dyn Read) -> Self {
Self {
input,
buf: vec![0; Self::DEFAULT_BUF_SIZE],
at: 0,
buf_read: 0,
}
}
pub fn new_with_size(input: &'s mut dyn Read, buf_size: usize) -> Self {
Self {
input,
buf: vec![0; buf_size],
at: 0,
buf_read: 0,
}
}
pub fn get(&mut self) -> Option<u8> {
if self.refill_buffer() {
let res = self.buf[self.at];
self.at += 1;
if res == b'\r' {
if self.refill_buffer() && self.buf[self.at] == b'\n' {
self.at += 1;
}
return Some(b'\n');
}
Some(res)
} else {
None
}
}
pub fn peek(&mut self) -> Option<u8> {
if self.refill_buffer() {
let res = self.buf[self.at];
Some(if res == b'\r' { b'\n' } else { res })
} else {
None
}
}
pub fn skip_whitespace(&mut self) {
while let Some(b) = self.peek() {
if !char::from(b).is_whitespace() {
return;
}
self.get();
}
}
pub fn next_token(&mut self) -> Option<Vec<u8>> {
self.skip_whitespace();
let mut res = Vec::new();
while let Some(c) = self.get() {
if char::from(c).is_whitespace() {
break;
}
res.push(c);
}
if res.is_empty() {
None
} else {
Some(res)
}
}
//noinspection RsSelfConvention
pub fn is_exhausted(&mut self) -> bool {
self.peek().is_none()
}
pub fn read<T: Readable>(&mut self) -> T {
T::read(self)
}
// used to read 1-indexed things when we 0-index internally
pub fn read1(&mut self) -> usize {
usize::read(self) - 1
}
pub fn read_vec<T: Readable>(&mut self, size: usize) -> Vec<T> {
let mut res = Vec::with_capacity(size);
for _ in 0..size {
res.push(self.read());
}
res
}
fn read_string(&mut self) -> String {
match self.next_token() {
None => {
panic!("Input exhausted");
}
Some(res) => unsafe { String::from_utf8_unchecked(res) },
}
}
fn read_integer<T: FromStr>(&mut self) -> T
where
<T as FromStr>::Err: Debug,
{
let res = self.read_string();
res.parse::<T>().unwrap()
}
fn read_float(&mut self) -> f64 {
let res = self.read_string();
res.parse::<f64>().unwrap()
}
pub fn read_char(&mut self) -> char {
self.skip_whitespace();
self.get().unwrap().into()
}
read_impl!(u32, read_unsigned, read_unsigned_vec);
read_impl!(u64, read_u64, read_u64_vec);
read_impl!(usize, read_size, read_size_vec, read_size_pair_vec);
read_impl!(i32, read_int, read_int_vec, read_int_pair_vec);
read_impl!(i64, read_long, read_long_vec, read_long_pair_vec);
read_impl!(i128, read_i128, read_i128_vec);
fn refill_buffer(&mut self) -> bool {
if self.at == self.buf_read {
self.at = 0;
self.buf_read = self.input.read(&mut self.buf).unwrap();
self.buf_read != 0
} else {
true
}
}
}
pub trait Readable {
fn read(input: &mut Input) -> Self;
}
impl Readable for char {
fn read(input: &mut Input) -> Self {
input.read_char()
}
}
impl Readable for f64 {
fn read(input: &mut Input) -> Self {
input.read_float()
}
}
impl<T: Readable> Readable for Vec<T> {
fn read(input: &mut Input) -> Self {
let size = input.read();
input.read_vec(size)
}
}
macro_rules! read_integer {
($($t:ident)+) => {$(
impl Readable for $t {
fn read(input: &mut Input) -> Self {
input.read_integer()
}
}
)+};
}
read_integer!(i8 i16 i32 i64 i128 isize u8 u16 u32 u64 u128 usize);
macro_rules! tuple_readable {
($($name:ident)+) => {
impl<$($name: Readable), +> Readable for ($($name,)+) {
fn read(input: &mut Input) -> Self {
($($name::read(input),)+)
}
}
}
}
tuple_readable! {T}
tuple_readable! {T U}
tuple_readable! {T U V}
tuple_readable! {T U V X}
tuple_readable! {T U V X Y}
tuple_readable! {T U V X Y Z}
tuple_readable! {T U V X Y Z A}
tuple_readable! {T U V X Y Z A B}
tuple_readable! {T U V X Y Z A B C}
tuple_readable! {T U V X Y Z A B C D}
tuple_readable! {T U V X Y Z A B C D E}
tuple_readable! {T U V X Y Z A B C D E F}
}
pub mod output {
use std::io::Write;
pub struct Output<'s> {
output: &'s mut dyn Write,
buf: Vec<u8>,
at: usize,
auto_flush: bool,
}
impl<'s> Output<'s> {
const DEFAULT_BUF_SIZE: usize = 4096;
pub fn new(output: &'s mut dyn Write) -> Self {
Self {
output,
buf: vec![0; Self::DEFAULT_BUF_SIZE],
at: 0,
auto_flush: false,
}
}
pub fn new_with_auto_flush(output: &'s mut dyn Write) -> Self {
Self {
output,
buf: vec![0; Self::DEFAULT_BUF_SIZE],
at: 0,
auto_flush: true,
}
}
pub fn flush(&mut self) {
if self.at != 0 {
self.output.write_all(&self.buf[..self.at]).unwrap();
self.output.flush().unwrap();
self.at = 0;
self.output.flush().expect("Couldn't flush output");
}
}
pub fn print<T: Writable>(&mut self, s: T) {
s.write(self);
}
pub fn print_line<T: Writable>(&mut self, s: T) {
self.print(s);
self.put(b'\n');
}
pub fn put(&mut self, b: u8) {
self.buf[self.at] = b;
self.at += 1;
if self.at == self.buf.len() {
self.flush();
}
}
pub fn maybe_flush(&mut self) {
if self.auto_flush {
self.flush();
}
}
pub fn print_per_line<T: Writable>(&mut self, arg: &[T]) {
for i in arg {
i.write(self);
self.put(b'\n');
}
}
pub fn print_iter<T: Writable, I: Iterator<Item = T>>(&mut self, iter: I) {
let mut first = true;
for e in iter {
if first {
first = false;
} else {
self.put(b' ');
}
e.write(self);
}
}
pub fn print_iter_ref<'a, T: 'a + Writable, I: Iterator<Item = &'a T>>(&mut self, iter: I) {
let mut first = true;
for e in iter {
if first {
first = false;
} else {
self.put(b' ');
}
e.write(self);
}
}
}
impl Write for Output<'_> {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
let mut start = 0usize;
let mut rem = buf.len();
while rem > 0 {
let len = (self.buf.len() - self.at).min(rem);
self.buf[self.at..self.at + len].copy_from_slice(&buf[start..start + len]);
self.at += len;
if self.at == self.buf.len() {
self.flush();
}
start += len;
rem -= len;
}
self.maybe_flush();
Ok(buf.len())
}
fn flush(&mut self) -> std::io::Result<()> {
self.flush();
Ok(())
}
}
pub trait Writable {
fn write(&self, output: &mut Output);
}
impl Writable for &str {
fn write(&self, output: &mut Output) {
output.write_all(self.as_bytes()).unwrap();
}
}
impl Writable for String {
fn write(&self, output: &mut Output) {
output.write_all(self.as_bytes()).unwrap();
}
}
impl Writable for char {
fn write(&self, output: &mut Output) {
output.put(*self as u8);
}
}
impl<T: Writable> Writable for [T] {
fn write(&self, output: &mut Output) {
output.print_iter_ref(self.iter());
}
}
impl<T: Writable, const N: usize> Writable for [T; N] {
fn write(&self, output: &mut Output) {
output.print_iter_ref(self.iter());
}
}
impl<T: Writable> Writable for &T {
fn write(&self, output: &mut Output) {
T::write(self, output)
}
}
impl<T: Writable> Writable for Vec<T> {
fn write(&self, output: &mut Output) {
self.as_slice().write(output);
}
}
impl Writable for bool {
fn write(&self, output: &mut Output) {
if *self {
"YES".to_string().write(output);
} else {
"NO".to_string().write(output);
}
}
}
macro_rules! write_to_string {
($($t:ident)+) => {$(
impl Writable for $t {
fn write(&self, output: &mut Output) {
self.to_string().write(output);
}
}
)+};
}
write_to_string!(u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize);
macro_rules! tuple_writable {
($name0:ident $($name:ident: $id:tt )*) => {
impl<$name0: Writable, $($name: Writable,)*> Writable for ($name0, $($name,)*) {
fn write(&self, out: &mut Output) {
self.0.write(out);
$(
out.put(b' ');
self.$id.write(out);
)*
}
}
}
}
tuple_writable! {T}
tuple_writable! {T U:1}
tuple_writable! {T U:1 V:2}
tuple_writable! {T U:1 V:2 X:3}
tuple_writable! {T U:1 V:2 X:3 Y:4}
tuple_writable! {T U:1 V:2 X:3 Y:4 Z:5}
tuple_writable! {T U:1 V:2 X:3 Y:4 Z:5 A:6}
impl<T: Writable> Writable for Option<T> {
fn write(&self, output: &mut Output) {
match self {
None => (-1).write(output),
Some(t) => t.write(output),
}
}
}
}
}
}
fn main() {
let mut sin = std::io::stdin();
let input = if false {
crate::algo_lib::io::input::Input::new_with_size(&mut sin, 1)
} else {
crate::algo_lib::io::input::Input::new(&mut sin)
};
let mut stdout = std::io::stdout();
let output = if false {
crate::algo_lib::io::output::Output::new_with_auto_flush(&mut stdout)
} else {
crate::algo_lib::io::output::Output::new(&mut stdout)
};
crate::solution::run(input, output);
}
提出情報
| 提出日時 |
|
| 問題 |
F - Visible Buildings |
| ユーザ |
qumeric |
| 言語 |
Rust (rustc 1.70.0) |
| 得点 |
0 |
| コード長 |
14886 Byte |
| 結果 |
WA |
| 実行時間 |
2210 ms |
| メモリ |
4984 KiB |
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
0 / 525 |
| 結果 |
|
|
| セット名 |
テストケース |
| 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 |
| ケース名 |
結果 |
実行時間 |
メモリ |
| hand_01.txt |
WA |
1 ms |
1908 KiB |
| hand_02.txt |
AC |
1 ms |
1952 KiB |
| hand_03.txt |
TLE |
2207 ms |
1948 KiB |
| hand_04.txt |
AC |
1 ms |
2092 KiB |
| random_01.txt |
TLE |
2207 ms |
4984 KiB |
| random_02.txt |
TLE |
2207 ms |
4180 KiB |
| random_03.txt |
TLE |
2207 ms |
3960 KiB |
| random_04.txt |
TLE |
2207 ms |
2964 KiB |
| random_05.txt |
TLE |
2210 ms |
4292 KiB |
| random_06.txt |
TLE |
2207 ms |
3088 KiB |
| random_07.txt |
TLE |
2210 ms |
2336 KiB |
| random_08.txt |
TLE |
2207 ms |
3448 KiB |
| random_09.txt |
TLE |
2207 ms |
2172 KiB |
| random_10.txt |
TLE |
2207 ms |
2592 KiB |
| random_11.txt |
TLE |
2207 ms |
3920 KiB |
| random_12.txt |
TLE |
2207 ms |
3316 KiB |
| random_13.txt |
WA |
7 ms |
2096 KiB |
| random_14.txt |
WA |
15 ms |
2444 KiB |
| random_15.txt |
WA |
53 ms |
4180 KiB |
| random_16.txt |
AC |
16 ms |
3864 KiB |
| random_17.txt |
TLE |
2207 ms |
3548 KiB |
| random_18.txt |
TLE |
2207 ms |
4280 KiB |
| random_19.txt |
TLE |
2207 ms |
3752 KiB |
| sample_01.txt |
AC |
1 ms |
1904 KiB |
| sample_02.txt |
AC |
0 ms |
2000 KiB |
| sample_03.txt |
AC |
1 ms |
1956 KiB |
| sample_04.txt |
AC |
1 ms |
1928 KiB |