結果
| 問題 |
No.1156 Nada Picnic 2
|
| ユーザー |
|
| 提出日時 | 2020-08-12 14:05:17 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 2,000 ms |
| コード長 | 1,962 bytes |
| コンパイル時間 | 13,134 ms |
| コンパイル使用メモリ | 391,516 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-09 18:14:04 |
| 合計ジャッジ時間 | 13,902 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 |
ソースコード
/*
use std::collections::HashMap;
fn next_permutation(lists: &mut Vec<usize>) -> bool {
let mut n = lists.len();
let mut i: usize = n - 1;
while i >= 1 && lists[i - 1] > lists[i] {
i -= 1;
}
if i == 0 { return false; }
let mut j: usize = i;
while j + 1 < n && lists[i - 1] < lists[j + 1] {
j += 1;
}
lists.swap(i-1, j);
n -= 1;
while n > i {
lists.swap(i, n);
i += 1;
n -= 1;
}
true
}
fn estimated_val(value_map: &HashMap<&char, &usize>, a: &str) -> usize {
let alen = a.len();
a.chars().enumerate().map(|pair| 10usize.pow(alen as u32 - pair.0 as u32 - 1u32) * value_map[&pair.1]).sum()
}
fn is_ok(value_map: &HashMap<&char, &usize>, a: &str, b: &str, c: &str) -> bool {
if value_map.get(&a.chars().nth(0).unwrap()).unwrap() == &&0 || value_map.get(&b.chars().nth(0).unwrap()).unwrap() == &&0 || value_map.get(&c.chars().nth(0).unwrap()).unwrap() == &&0 {
return false;
}
estimated_val(value_map, a) + estimated_val(value_map, b) == estimated_val(value_map, c)
}
fn solver(a: &str, b: &str, c: &str) {
let mut cands: Vec<usize> = (0..=9).collect();
let mut clist: Vec<char> = vec![a, b, c].iter().map(|s| s.chars().collect::<Vec<char>>()).flatten().collect();
clist.sort();
clist.dedup();
loop {
let value_map: HashMap<&char, &usize> = clist.iter().zip(cands.iter().take(clist.len())).collect();
if is_ok(&value_map, a, b, c) {
println!("{:?}", value_map);
return;
}
if !next_permutation(&mut cands) { break; }
}
panic!("error");
}
*/
fn main() {
let mut n = String::new();
std::io::stdin().read_line(&mut n).ok();
let n: usize = n.trim().parse().unwrap();
//solver("abc", "def", "ghcg");
//solver("aabc", "defg", "hibcj");
//solver("spring", "eight", "picnic");
let result = if n == 1 { 1251 } else if n == 2 { 10947 } else { 841341 };
println!("{}", result);
}