ABC202 write up
abc202にバーチャル参加しました.
ABCの3完で終了後Dを解説ACしたので書きます.
A - Three Dice
サイコロはある面とその反対の面の目を足し合わせると
#![allow(unused_imports)]
#![allow(non_snake_case)]
use proconio::{fastout, input, marker::*};
fn main() {
input! {
mut a:usize,
mut b:usize,
mut c:usize
}
a = 7 - a;
b = 7 - b;
c = 7 - c;
println!("{}", a + b + c);
}
B - 180°
となるように変換する問題. 問題文に指示されたように文字列を弄る
#![allow(unused_imports)]
#![allow(non_snake_case)]
use proconio::{fastout, input, marker::*};
fn main() {
input! {
s:Chars
}
for i in s.into_iter().rev() {
let a = match i {
'0' => '0',
'1' => '1',
'6' => '9',
'8' => '8',
'9' => '6',
_ => '_',
};
print!("{}", a);
}
println!("");
}
C - Made Up
愚直に
#![allow(unused_imports)]
#![allow(non_snake_case)]
use cmp::{max, min, Reverse};
use proconio::{fastout, input, marker::*};
use std::collections::*;
use std::*;
fn main() {
input! {
n:usize,
a:[i64;n],
b:[i64;n],
c:[usize;n]
}
let mut h = HashMap::new();
for i in c {
*h.entry(b[i - 1]).or_insert(0) += 1;
}
dbg!(&h);
let mut ans:i64 = 0;
for i in a {
ans += h.get(&i).unwrap_or(&0);
}
println!("{}", ans);
}
D - aab aba baa
むずかしかった...解説ACしました
辞書順配列は先頭の文字から考えると良いらしい.なので答えになる文字列を
もし,
なので
イメージ的に2分探索みたいだな〜と思って書いてました.違うけど
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::{max, min, Reverse};
use std::collections::*;
use proconio::{fastout, input, marker::*};
use num::integer::binomial;
fn main() {
input! {
mut a:i64,
mut b:i64,
mut k:i64
}k -= 1;
let n = a+b;
let mut ans = String::new();
for i in 0..n {
if a > 0 {
let aCb = binomial(a+b-1,b);
if k < aCb {
ans.push('a');
a -= 1;
}else{
ans.push('b');
b -= 1;
k -= aCb;
}
}else{
ans.push('b');
b -= 1;
}
}
println!("{}",ans);
}
もしかしたら別解?
試してないのでWAるかもしれませんが,
Discussion