結果

問題 No.1319 最強とんがりコーン
ユーザー くれちーくれちー
提出日時 2020-12-16 01:32:35
言語 Rust
(1.77.0 + proconio)
結果
WA  
実行時間 -
コード長 7,973 bytes
コンパイル時間 14,380 ms
コンパイル使用メモリ 377,080 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-20 04:09:21
合計ジャッジ時間 61,262 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 784 ms
5,376 KB
testcase_02 AC 555 ms
5,376 KB
testcase_03 WA -
testcase_04 AC 854 ms
5,376 KB
testcase_05 AC 650 ms
5,376 KB
testcase_06 AC 573 ms
5,376 KB
testcase_07 AC 599 ms
5,376 KB
testcase_08 AC 574 ms
5,376 KB
testcase_09 AC 699 ms
5,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 579 ms
5,376 KB
testcase_13 AC 560 ms
5,376 KB
testcase_14 AC 625 ms
5,376 KB
testcase_15 AC 561 ms
5,376 KB
testcase_16 AC 617 ms
5,376 KB
testcase_17 AC 806 ms
5,376 KB
testcase_18 AC 609 ms
5,376 KB
testcase_19 AC 848 ms
5,376 KB
testcase_20 WA -
testcase_21 AC 781 ms
5,376 KB
testcase_22 AC 750 ms
5,376 KB
testcase_23 AC 754 ms
5,376 KB
testcase_24 AC 780 ms
5,376 KB
testcase_25 AC 771 ms
5,376 KB
testcase_26 AC 753 ms
5,376 KB
testcase_27 AC 754 ms
5,376 KB
testcase_28 AC 766 ms
5,376 KB
testcase_29 AC 755 ms
5,376 KB
testcase_30 AC 761 ms
5,376 KB
testcase_31 AC 780 ms
5,376 KB
testcase_32 AC 564 ms
5,376 KB
testcase_33 AC 895 ms
5,376 KB
testcase_34 WA -
testcase_35 AC 776 ms
5,376 KB
testcase_36 AC 786 ms
5,376 KB
testcase_37 AC 797 ms
5,376 KB
testcase_38 AC 759 ms
5,376 KB
testcase_39 AC 869 ms
5,376 KB
testcase_40 AC 564 ms
5,376 KB
testcase_41 AC 654 ms
5,376 KB
testcase_42 AC 625 ms
5,376 KB
testcase_43 AC 654 ms
5,376 KB
testcase_44 AC 630 ms
5,376 KB
testcase_45 AC 689 ms
5,376 KB
testcase_46 AC 646 ms
5,376 KB
testcase_47 AC 639 ms
5,376 KB
testcase_48 WA -
testcase_49 AC 630 ms
5,376 KB
testcase_50 AC 632 ms
5,376 KB
testcase_51 AC 665 ms
5,376 KB
testcase_52 AC 660 ms
5,376 KB
testcase_53 WA -
testcase_54 AC 622 ms
5,376 KB
testcase_55 AC 636 ms
5,376 KB
testcase_56 AC 653 ms
5,376 KB
testcase_57 AC 695 ms
5,376 KB
testcase_58 AC 702 ms
5,376 KB
testcase_59 AC 715 ms
5,376 KB
testcase_60 AC 213 ms
5,376 KB
testcase_61 AC 205 ms
5,376 KB
testcase_62 AC 210 ms
5,376 KB
testcase_63 AC 576 ms
5,376 KB
testcase_64 AC 572 ms
5,376 KB
testcase_65 AC 580 ms
5,376 KB
testcase_66 AC 205 ms
5,376 KB
testcase_67 AC 772 ms
5,376 KB
testcase_68 AC 747 ms
5,376 KB
testcase_69 AC 778 ms
5,376 KB
testcase_70 AC 643 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// The main code is at the very bottom.

#[allow(unused_imports)]
use {
  lib::byte::ByteChar,
  std::cell::{Cell, RefCell},
  std::cmp::{
    self,
    Ordering::{self, *},
    Reverse,
  },
  std::collections::*,
  std::convert::identity,
  std::fmt::{self, Debug, Display, Formatter},
  std::io::prelude::*,
  std::iter::{self, FromIterator},
  std::marker::PhantomData,
  std::mem,
  std::num::Wrapping,
  std::ops::{Range, RangeFrom, RangeInclusive, RangeTo, RangeToInclusive},
  std::process,
  std::rc::Rc,
  std::thread,
  std::time::{Duration, Instant},
  std::{char, f32, f64, i128, i16, i32, i64, i8, isize, str, u128, u16, u32, u64, u8, usize},
};

#[allow(unused_imports)]
#[macro_use]
pub mod lib {
  pub mod byte {
    pub use self::byte_char::*;

    mod byte_char {
      use std::error::Error;
      use std::fmt::{self, Debug, Display, Formatter};
      use std::str::FromStr;

      #[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
      #[repr(transparent)]
      pub struct ByteChar(pub u8);

      impl Debug for ByteChar {
        fn fmt(&self, f: &mut Formatter) -> fmt::Result {
          write!(f, "b'{}'", self.0 as char)
        }
      }

      impl Display for ByteChar {
        fn fmt(&self, f: &mut Formatter) -> fmt::Result {
          write!(f, "{}", self.0 as char)
        }
      }

      impl FromStr for ByteChar {
        type Err = ParseByteCharError;

        fn from_str(s: &str) -> Result<ByteChar, ParseByteCharError> {
          match s.as_bytes().len() {
            1 => Ok(ByteChar(s.as_bytes()[0])),
            0 => Err(ParseByteCharErrorKind::EmptyStr.into()),
            _ => Err(ParseByteCharErrorKind::TooManyBytes.into()),
          }
        }
      }

      #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
      pub struct ParseByteCharError {
        kind: ParseByteCharErrorKind,
      }

      impl Display for ParseByteCharError {
        fn fmt(&self, f: &mut Formatter) -> fmt::Result {
          f.write_str(match self.kind {
            ParseByteCharErrorKind::EmptyStr => "empty string",
            ParseByteCharErrorKind::TooManyBytes => "too many bytes",
          })
        }
      }

      impl Error for ParseByteCharError {}

      #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
      enum ParseByteCharErrorKind {
        EmptyStr,
        TooManyBytes,
      }

      impl From<ParseByteCharErrorKind> for ParseByteCharError {
        fn from(kind: ParseByteCharErrorKind) -> ParseByteCharError {
          ParseByteCharError { kind }
        }
      }
    }
  }

  pub mod io {
    pub use self::scanner::*;

    mod scanner {
      use std::io::{self, BufRead};
      use std::iter;
      use std::str::FromStr;

      #[derive(Debug)]
      pub struct Scanner<R> {
        reader: R,
        buf: String,
        pos: usize,
      }

      impl<R: BufRead> Scanner<R> {
        pub fn new(reader: R) -> Self {
          Scanner {
            reader,
            buf: String::new(),
            pos: 0,
          }
        }

        pub fn next(&mut self) -> io::Result<&str> {
          let start = loop {
            match self.rest().find(|c| c != ' ') {
              Some(i) => break i,
              None => self.fill_buf()?,
            }
          };
          self.pos += start;
          let len = self.rest().find(' ').unwrap_or(self.rest().len());
          let s = &self.buf[self.pos..][..len]; // self.rest()[..len]
          self.pos += len;
          Ok(s)
        }

        pub fn parse_next<T>(&mut self) -> io::Result<Result<T, T::Err>>
        where
          T: FromStr,
        {
          Ok(self.next()?.parse())
        }

        pub fn parse_next_n<T>(&mut self, n: usize) -> io::Result<Result<Vec<T>, T::Err>>
        where
          T: FromStr,
        {
          iter::repeat_with(|| self.parse_next()).take(n).collect()
        }

        pub fn map_next_bytes<T, F>(&mut self, mut f: F) -> io::Result<Vec<T>>
        where
          F: FnMut(u8) -> T,
        {
          Ok(self.next()?.bytes().map(&mut f).collect())
        }

        pub fn map_next_bytes_n<T, F>(&mut self, n: usize, mut f: F) -> io::Result<Vec<Vec<T>>>
        where
          F: FnMut(u8) -> T,
        {
          iter::repeat_with(|| self.map_next_bytes(&mut f))
            .take(n)
            .collect()
        }

        fn rest(&self) -> &str {
          &self.buf[self.pos..]
        }

        fn fill_buf(&mut self) -> io::Result<()> {
          self.buf.clear();
          self.pos = 0;
          let read = self.reader.read_line(&mut self.buf)?;
          if read == 0 {
            return Err(io::ErrorKind::UnexpectedEof.into());
          }
          if *self.buf.as_bytes().last().unwrap() == b'\n' {
            self.buf.pop();
          }
          Ok(())
        }
      }
    }
  }
}

#[allow(unused_macros)]
macro_rules! eprint {
  ($($arg:tt)*) => {
    if cfg!(debug_assertions) {
      std::eprint!($($arg)*)
    }
  };
}
#[allow(unused_macros)]
macro_rules! eprintln {
  ($($arg:tt)*) => {
    if cfg!(debug_assertions) {
      std::eprintln!($($arg)*)
    }
  };
}
#[allow(unused_macros)]
macro_rules! dbg {
  ($($arg:tt)*) => {
    if cfg!(debug_assertions) {
      std::dbg!($($arg)*)
    } else {
      ($($arg)*)
    }
  };
}

const CUSTOM_STACK_SIZE_MIB: Option<usize> = Some(1024);
const INTERACTIVE: bool = false;

fn main() -> std::io::Result<()> {
  match CUSTOM_STACK_SIZE_MIB {
    Some(stack_size_mib) => std::thread::Builder::new()
      .name("run_solver".to_owned())
      .stack_size(stack_size_mib * 1024 * 1024)
      .spawn(run_solver)?
      .join()
      .unwrap(),
    None => run_solver(),
  }
}

fn run_solver() -> std::io::Result<()> {
  let stdin = std::io::stdin();
  let reader = stdin.lock();
  let stdout = std::io::stdout();
  let writer = stdout.lock();
  macro_rules! with_wrapper {
    ($($wrapper:expr)?) => {{
      let mut writer = $($wrapper)?(writer);
      solve(reader, &mut writer)?;
      writer.flush()
    }};
  }
  if cfg!(debug_assertions) || INTERACTIVE {
    with_wrapper!()
  } else {
    with_wrapper!(std::io::BufWriter::new)
  }
}

fn solve<R, W>(reader: R, mut writer: W) -> std::io::Result<()>
where
  R: BufRead,
  W: Write,
{
  let mut _scanner = lib::io::Scanner::new(reader);
  #[allow(unused_macros)]
  macro_rules! scan {
    ($T:ty) => {
      _scanner.parse_next::<$T>()?.unwrap()
    };
    ($($T:ty),+) => {
      ($(scan!($T)),+)
    };
    ($T:ty; $n:expr) => {
      _scanner.parse_next_n::<$T>($n)?.unwrap()
    };
    ($($T:ty),+; $n:expr) => {
      iter::repeat_with(|| -> std::io::Result<_> { Ok(($(scan!($T)),+)) })
        .take($n)
        .collect::<std::io::Result<Vec<_>>>()?
    };
  }
  #[allow(unused_macros)]
  macro_rules! scan_bytes_map {
    ($f:expr) => {
      _scanner.map_next_bytes($f)?
    };
    ($f:expr; $n:expr) => {
      _scanner.map_next_bytes_n($n, $f)?
    };
  }
  #[allow(unused_macros)]
  macro_rules! print {
    ($($arg:tt)*) => {
      write!(writer, $($arg)*)?
    };
  }
  #[allow(unused_macros)]
  macro_rules! println {
    ($($arg:tt)*) => {
      writeln!(writer, $($arg)*)?
    };
  }
  #[allow(unused_macros)]
  macro_rules! answer {
    ($($arg:tt)*) => {{
      println!($($arg)*);
      return Ok(());
    }};
  }
  {
    #[allow(non_snake_case)]
    let (R, H, D) = scan!(f64, f64, f64);

    let r = |y: f64| R * y / H;
    let t = |y: f64| f64::consts::PI - (1.0 - D.powi(2) / (2.0 * r(y).powi(2))).acos();
    let s = |y: f64| {
      let t = t(y);
      r(y).powi(2) * (t - t.sin())
    };

    let a = H * D / (2.0 * R);
    let b = H;
    let n = 16_000_000u32;
    let h = (b - a) / n as f64;
    let y = |i| a + i as f64 * h;
    let mut v = 0.0;
    v += s(y(0));
    v += 2.0 * (1..=n / 2 - 1).map(|i| s(y(2 * i))).sum::<f64>();
    v += 4.0 * (1..=n / 2).map(|i| s(y(2 * i - 1))).sum::<f64>();
    v += s(y(n));
    v *= h / 3.0;
    println!("{}", v);
  }
  #[allow(unreachable_code)]
  Ok(())
}
0