結果
問題 | No.329 全射 |
ユーザー | koba-e964 |
提出日時 | 2016-12-27 16:50:48 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 71 ms / 2,000 ms |
コード長 | 2,376 bytes |
コンパイル時間 | 12,505 ms |
コンパイル使用メモリ | 405,504 KB |
実行使用メモリ | 10,752 KB |
最終ジャッジ日時 | 2024-12-15 03:34:21 |
合計ジャッジ時間 | 13,650 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 8 ms
9,728 KB |
testcase_01 | AC | 8 ms
9,728 KB |
testcase_02 | AC | 8 ms
9,728 KB |
testcase_03 | AC | 9 ms
9,728 KB |
testcase_04 | AC | 9 ms
9,728 KB |
testcase_05 | AC | 8 ms
9,728 KB |
testcase_06 | AC | 8 ms
9,856 KB |
testcase_07 | AC | 8 ms
9,856 KB |
testcase_08 | AC | 7 ms
9,728 KB |
testcase_09 | AC | 8 ms
9,728 KB |
testcase_10 | AC | 9 ms
9,728 KB |
testcase_11 | AC | 8 ms
9,728 KB |
testcase_12 | AC | 9 ms
9,728 KB |
testcase_13 | AC | 67 ms
10,572 KB |
testcase_14 | AC | 20 ms
9,856 KB |
testcase_15 | AC | 40 ms
10,368 KB |
testcase_16 | AC | 56 ms
10,704 KB |
testcase_17 | AC | 46 ms
10,368 KB |
testcase_18 | AC | 71 ms
10,752 KB |
testcase_19 | AC | 63 ms
10,496 KB |
testcase_20 | AC | 63 ms
10,624 KB |
testcase_21 | AC | 53 ms
10,368 KB |
testcase_22 | AC | 44 ms
10,240 KB |
testcase_23 | AC | 25 ms
10,240 KB |
testcase_24 | AC | 23 ms
10,112 KB |
testcase_25 | AC | 34 ms
10,368 KB |
testcase_26 | AC | 20 ms
9,984 KB |
testcase_27 | AC | 10 ms
9,856 KB |
testcase_28 | AC | 9 ms
9,728 KB |
testcase_29 | AC | 9 ms
9,728 KB |
testcase_30 | AC | 9 ms
9,728 KB |
testcase_31 | AC | 8 ms
9,728 KB |
testcase_32 | AC | 9 ms
9,856 KB |
testcase_33 | AC | 9 ms
9,728 KB |
testcase_34 | AC | 9 ms
9,856 KB |
testcase_35 | AC | 10 ms
9,856 KB |
testcase_36 | AC | 10 ms
9,728 KB |
testcase_37 | AC | 9 ms
9,728 KB |
testcase_38 | AC | 10 ms
9,856 KB |
testcase_39 | AC | 10 ms
9,856 KB |
testcase_40 | AC | 10 ms
9,856 KB |
testcase_41 | AC | 10 ms
9,728 KB |
testcase_42 | AC | 10 ms
9,728 KB |
ソースコード
#[allow(unused_imports)] use std::cmp::*; #[allow(unused_imports)] use std::collections::*; use std::io::*; #[allow(dead_code)] fn getline() -> String { let mut ret = String::new(); std::io::stdin().read_line(&mut ret).ok(); return ret; } fn get_word() -> String { let mut stdin = std::io::stdin(); let mut u8b: [u8; 1] = [0]; loop { let mut buf: Vec<u8> = Vec::with_capacity(16); loop { let res = stdin.read(&mut u8b); if res.is_err() || res.ok().unwrap() == 0 || u8b[0] <= ' ' as u8 { break; } else { buf.push(u8b[0]); } } if buf.len() >= 1 { let ret = std::string::String::from_utf8(buf).unwrap(); return ret; } } } fn parse<T: std::str::FromStr>(s: &str) -> T { s.parse::<T>().ok().unwrap() } #[allow(dead_code)] fn get<T: std::str::FromStr>() -> T { parse(&get_word()) } fn main() { let n: usize = get(); let m: usize = get(); let w: Vec<usize> = (0 .. n).map(|_| get()).collect(); let e: Vec<(usize, usize)> = (0 .. m).map(|_| { let u: usize = get(); let v: usize = get(); (u - 1, v - 1)}).collect(); let md: i64 = 1_000_000_007; let mut tot: i64 = 0; // precompute the number of surjections, for all w_1, w_2 const W: usize = 1001; let mut surj: Vec<Vec<i64>> = vec![vec![0; W]; W]; surj[0][0] = 1; for i in 1 .. W { for j in 1 .. W { let tmp = (j as i64) * (surj[i - 1][j] + surj[i - 1][j - 1]); surj[i][j] = tmp % md; } } for i in 0 .. n { // collect all j s.t. w[j] >= w[i] let mut edges: Vec<Vec<usize>> = vec![Vec::new(); n]; for &(u, v) in &e { if w[u] >= w[i] && w[v] >= w[i] { edges[v].push(u); } } let mut reach: Vec<bool> = vec![false; n]; let mut que: VecDeque<usize> = VecDeque::new(); que.push_back(i); while let Some(v) = que.pop_front() { if reach[v] { continue; } reach[v] = true; for &w in &edges[v] { que.push_back(w); } } for j in 0 .. n { if reach[j] { tot = (tot + surj[w[j]][w[i]]) % md; } } } println!("{}", tot); }