結果
問題 | No.171 スワップ文字列(Med) |
ユーザー |
|
提出日時 | 2022-01-30 23:40:19 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 170 ms / 1,000 ms |
コード長 | 1,465 bytes |
コンパイル時間 | 16,821 ms |
コンパイル使用メモリ | 379,732 KB |
実行使用メモリ | 40,456 KB |
最終ジャッジ日時 | 2024-06-11 08:29:13 |
合計ジャッジ時間 | 16,495 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 |
ソースコード
#[macro_export]macro_rules! setup {{ mut $input:ident: SplitWhitespace $(,)? } => {use std::io::Read;let mut buf = String::new();std::io::stdin().read_to_string(&mut buf).ok();let mut $input = buf.split_whitespace();};}#[macro_export]macro_rules! parse_next {($str_iter:expr) => {$str_iter.next().unwrap().parse().ok().unwrap()};}#[allow(unused_imports)]use std::collections::{HashMap, HashSet, VecDeque};fn main() {setup! { mut input: SplitWhitespace };let s: String = parse_next!(input);const MOD: u64 = 573;let mut cs = HashMap::new();s.chars().for_each(|c| {if let Some(count) = cs.get_mut(&c) {*count += 1;} else {cs.insert(c, 1 as u64);}});let mut comb = HashMap::new();for i in 0..=(s.len() as u64) {for j in 0..=i {if j == 0 || j == i {comb.insert((i, j), 1);} else {let left = comb[&(i - 1, j - 1)];let right = comb[&(i - 1, j)];comb.insert((i, j), (left + right) % MOD);}}}let ans = (|| {let mut ret = 1;let mut len = s.len() as u64;for count in cs.values() {ret = (ret * comb[&(len, *count)]) % MOD;len -= *count;}(ret + MOD - 1) % MOD})();println!("{}", ans);}