結果
問題 | No.58 イカサマなサイコロ |
ユーザー | aimy |
提出日時 | 2017-11-19 14:43:20 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 4,901 ms / 5,000 ms |
コード長 | 3,614 bytes |
コンパイル時間 | 13,563 ms |
コンパイル使用メモリ | 379,632 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-05-04 11:59:53 |
合計ジャッジ時間 | 65,242 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4,900 ms
5,248 KB |
testcase_01 | AC | 4,900 ms
5,376 KB |
testcase_02 | AC | 4,900 ms
5,376 KB |
testcase_03 | AC | 4,901 ms
5,376 KB |
testcase_04 | AC | 4,901 ms
5,376 KB |
testcase_05 | AC | 4,900 ms
5,376 KB |
testcase_06 | AC | 4,901 ms
5,376 KB |
testcase_07 | AC | 4,900 ms
5,376 KB |
testcase_08 | AC | 4,900 ms
5,376 KB |
testcase_09 | AC | 4,900 ms
5,376 KB |
コンパイルメッセージ
warning: use of deprecated method `core::str::<impl str>::trim_right`: superseded by `trim_end` --> src/main.rs:79:9 | 79 | buf.trim_right().parse::<T>().ok().unwrap() | ^^^^^^^^^^ | = note: `#[warn(deprecated)]` on by default help: replace the use of the deprecated method | 79 | buf.trim_end().parse::<T>().ok().unwrap() | ~~~~~~~~ warning: use of deprecated method `core::str::<impl str>::trim_right`: superseded by `trim_end` --> src/main.rs:94:22 | 94 | let mut it = buf.trim_right().split_whitespace(); | ^^^^^^^^^^ | help: replace the use of the deprecated method | 94 | let mut it = buf.trim_end().split_whitespace(); | ~~~~~~~~ warning: use of deprecated method `core::str::<impl str>::trim_right`: superseded by `trim_end` --> src/main.rs:112:22 | 112 | let mut it = buf.trim_right().split_whitespace(); | ^^^^^^^^^^ | help: replace the use of the deprecated method | 112 | let mut it = buf.trim_end().split_whitespace(); | ~~~~~~~~ warning: use of deprecated method `core::str::<impl str>::trim_right`: superseded by `trim_end` --> src/main.rs:131:9 | 131 | buf.trim_right().split_whitespace().map(|t| t.parse::<T>().ok().unwrap()).collect() | ^^^^^^^^^^ | help: replace the use of the deprecated method | 131 | buf.trim_end().split_whitespace().map(|t| t.parse::<T>().ok().unwrap()).collect() | ~~~~~~~~ warning: use of deprecated method `core::str::<impl str>::trim_right`: superseded by `trim_end` --> src/main.rs:146:9 | 146 | buf.trim_right().chars().collect() | ^^^^^^^^^^ | help: replace the use of the deprecated method | 146 | buf.trim_end().chars().collect() | ~~~~~~~~
ソースコード
fn main() { let n = get::val::<usize>(); let k = get::val::<usize>(); let t = Time::new(); let mut rand = XorShift::new(); let mut count = 0; let mut win = 0; while t.elapsed() < 4.9 { let taro: u64 = (0..n-k).map(|_|rand.from_to(1,6)).sum::<u64>() + (0..k).map(|_|rand.from_to(4,6)).sum::<u64>(); let jiro: u64 = (0..n).map(|_|rand.from_to(1,6)).sum::<u64>(); if taro > jiro {win += 1} count += 1 } println!("{}", win as f64 / count as f64) } use std::time::*; struct Time { start: Instant } #[allow(dead_code)] impl Time { fn new() -> Time { Time {start: Instant::now()} } fn elapsed(&self) -> f64 { let sec = self.start.elapsed().as_secs() as f64; let nano = self.start.elapsed().subsec_nanos() as f64 / 1000000000.0; sec + nano } } #[derive(Copy, Clone)] struct XorShift { state1: u64, state2: u64 } #[allow(dead_code)] impl XorShift { fn new() -> XorShift { use std::time::*; let start = Instant::now(); let seed1 = start.elapsed().subsec_nanos() as u64; let seed2 = start.elapsed().subsec_nanos() as u64; XorShift {state1: seed1, state2: seed2} } fn next(&mut self) -> u64 { let mut s1 = self.state2; let mut s2 = self.state1; s1 = s1 ^ (s1 >> 26); s2 = s2 ^ (s2 << 23); s2 = s2 ^ (s2 >> 17); self.state1 = self.state2; self.state2 = s1 ^ s2; (self.state1 >> 1) + (self.state2 >> 1) } fn from_to(&mut self, from: u64, to: u64) -> u64 { self.next() % (to - from + 1) + from } } #[allow(dead_code)] mod get { use std::io::*; use std::str::*; pub fn val<T: FromStr>() -> T { let mut buf = String::new(); let s = stdin(); s.lock().read_line(&mut buf).ok(); buf.trim_right().parse::<T>().ok().unwrap() } pub fn vals<T: FromStr>(n: usize) -> Vec<T> { let mut vec: Vec<T> = vec![]; for _ in 0 .. n { vec.push(val()); } vec } pub fn tuple<T1: FromStr, T2: FromStr>() -> (T1, T2) { let mut buf = String::new(); let s = stdin(); s.lock().read_line(&mut buf).ok(); let mut it = buf.trim_right().split_whitespace(); let x = it.next().unwrap().parse::<T1>().ok().unwrap(); let y = it.next().unwrap().parse::<T2>().ok().unwrap(); (x, y) } pub fn tuples<T1: FromStr, T2: FromStr>(n: usize) -> Vec<(T1, T2)> { let mut vec: Vec<(T1, T2)> = vec![]; for _ in 0 .. n { vec.push(tuple()); } vec } pub fn tuple3<T1: FromStr, T2: FromStr, T3: FromStr>() -> (T1, T2, T3) { let mut buf = String::new(); let s = stdin(); s.lock().read_line(&mut buf).ok(); let mut it = buf.trim_right().split_whitespace(); let x = it.next().unwrap().parse::<T1>().ok().unwrap(); let y = it.next().unwrap().parse::<T2>().ok().unwrap(); let z = it.next().unwrap().parse::<T3>().ok().unwrap(); (x, y, z) } pub fn tuple3s<T1: FromStr, T2: FromStr, T3: FromStr>(n: usize) -> Vec<(T1, T2, T3)> { let mut vec: Vec<(T1, T2, T3)> = vec![]; for _ in 0 .. n { vec.push(tuple3()); } vec } pub fn list<T: FromStr>() -> Vec<T> { let mut buf = String::new(); let s = stdin(); s.lock().read_line(&mut buf).ok(); buf.trim_right().split_whitespace().map(|t| t.parse::<T>().ok().unwrap()).collect() } pub fn lists<T: FromStr>(h: usize) -> Vec<Vec<T>> { let mut mat: Vec<Vec<T>> = vec![]; for _ in 0 .. h { mat.push(list()); } mat } pub fn chars() -> Vec<char> { let mut buf = String::new(); let s = stdin(); s.lock().read_line(&mut buf).ok(); buf.trim_right().chars().collect() } }