結果
問題 | No.133 カードゲーム |
ユーザー |
|
提出日時 | 2025-05-10 06:02:17 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 1 ms / 5,000 ms |
コード長 | 1,408 bytes |
コンパイル時間 | 11,518 ms |
コンパイル使用メモリ | 400,284 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-05-10 06:02:31 |
合計ジャッジ時間 | 12,631 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 19 |
ソースコード
/* * Author: srtry * Created: 2025-05-10T01:29:57+09:00 * Coding: utf-8-unix */ use proconio::input; use std::io::{stdout,Write,BufWriter}; fn permutations(vec:&Vec<u8>) -> Option<Vec<Vec<u8>>> { if vec.len()==0 { return None; } if vec.len()==1 { return Some(vec![vec.clone()]); } let mut vec_ = vec.clone(); let tmp:u8 = vec_.remove(0); let mut tmp2:Vec<u8>; let mut res = Vec::new(); let pre = permutations(&vec_).unwrap(); for elem in pre.iter() { for i in 0..=elem.len() { tmp2 = elem.clone(); tmp2.insert(i,tmp); res.push(tmp2); } } return Some(res); } fn main() { input!{ n:usize, a:[u8;n], b:[u8;n], } let out = stdout(); let mut out = BufWriter::new(out.lock()); // Aの並びは固定 Bの並び全パターン let b_ps = permutations(&b).unwrap(); let mut win_games = 0; for b_p in b_ps.iter() { let mut win_cnt:u8 = 0; let mut lose_cnt:u8 = 0; for i in 0..n { if a[i] > b_p[i] { win_cnt += 1; } else if a[i] < b_p[i] { lose_cnt += 1; } } if win_cnt > lose_cnt { win_games += 1; } } write!(out, "{}", (win_games as f32)/(b_ps.len() as f32)).unwrap(); }