結果
問題 | No.133 カードゲーム |
ユーザー |
|
提出日時 | 2024-05-01 14:16:51 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 1 ms / 5,000 ms |
コード長 | 2,278 bytes |
コンパイル時間 | 13,337 ms |
コンパイル使用メモリ | 378,656 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-21 19:07:48 |
合計ジャッジ時間 | 14,453 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 19 |
コンパイルメッセージ
warning: constant `DX` is never used --> src/main.rs:18:7 | 18 | const DX: [i64; 4] = [0, 0, 1, -1]; | ^^ | = note: `#[warn(dead_code)]` on by default warning: constant `DY` is never used --> src/main.rs:19:7 | 19 | const DY: [i64; 4] = [1, -1, 0, 0]; | ^^
ソースコード
#![allow(non_snake_case)]#![allow(unused_imports)]use crate::lib::Permutation;use proconio::{fastout, input, input_interactive,marker::{Chars, Isize1, Usize1},};use std::vec;#[allow(dead_code)]// const MOD: i64 = 1_000_000_007;// const MOD : i64 = 1_000_000_009;const MOD: i64 = 998_244_353;#[allow(dead_code)]const INF: i64 = 1_010_000_000_000_000_017;const DX: [i64; 4] = [0, 0, 1, -1];const DY: [i64; 4] = [1, -1, 0, 0];#[allow(non_snake_case)]fn main() {input!(N:usize, A:[usize;N], B:[usize;N]);let mut count_match = 0;let mut count_win_A = 0;let p = Permutation::new(&(0..N).collect());for perm_A in p.clone() {for perm_B in p.clone() {count_match += 1;let mut win_A = 0;for i in 0..N {if A[perm_A[i]] > B[perm_B[i]] {win_A += 1;}}if win_A > N / 2 {count_win_A += 1;}}}println!("{}", count_win_A as f64 / count_match as f64)}pub mod lib {#[derive(Clone)]pub struct Permutation<T: Clone> {v: Vec<T>,l: Vec<usize>,not_start: bool,}impl<T: Clone> Permutation<T> {pub fn new(v: &Vec<T>) -> Permutation<T> {Permutation {l: vec![0; v.len()],v: v.clone(),not_start: true,}}}impl<T: Clone> Iterator for Permutation<T> {type Item = Vec<T>;fn next(&mut self) -> Option<Vec<T>> {// non-permutated vectorif self.not_start {self.not_start = false;return Some(self.v.clone());}for n in 0..self.v.len() {if self.l[n] < n {if (n + 1) % 2 == 1 {self.v.swap(0, n);self.l[n] += 1;} else {self.v.swap(self.l[n], n);self.l[n] += 1;}return Some(self.v.clone());} else {self.l[n] = 0}}return None;}}}