Skip to content

Commit

Permalink
tessoku-book c06-c08
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Dec 20, 2022
1 parent 0767a4a commit 19d41dc
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 12 deletions.
9 changes: 5 additions & 4 deletions tessoku-book/src/bin/c06.rs
@@ -1,10 +1,11 @@
use proconio::{input, marker::Usize1};
use proconio::input;

fn main() {
input! {
n: usize,
a: [Usize1; n],
};
let ans = n - a.len();
println!("{}", ans);
println!("{}", n);
for i in 0..n {
println!("{} {}", i + 1, (i + 1) % n + 1);
}
}
22 changes: 18 additions & 4 deletions tessoku-book/src/bin/c07.rs
@@ -1,10 +1,24 @@
use proconio::{input, marker::Usize1};
use proconio::input;
use superslice::Ext;

fn main() {
input! {
n: usize,
a: [Usize1; n],
mut c: [usize; n],
q: usize,
x: [usize; q],
};
let ans = n - a.len();
println!("{}", ans);

c.sort();
let cs = std::iter::once(0)
.chain(c.iter().scan(0, |acc, &i| {
*acc += i;
Some(*acc)
}))
.collect::<Vec<usize>>();

for x_j in x {
let count = cs.lower_bound(&(x_j + 1)).saturating_sub(1);
println!("{}", count);
}
}
50 changes: 46 additions & 4 deletions tessoku-book/src/bin/c08.rs
@@ -1,10 +1,52 @@
use proconio::{input, marker::Usize1};
use proconio::{input, marker::Chars};

fn main() {
input! {
n: usize,
a: [Usize1; n],
st: [(Chars, usize); n],
};
let ans = n - a.len();
println!("{}", ans);

let mut ans = vec![];
for x in 0..=9999 {
let x = format!("{:04}", x).chars().collect::<Vec<char>>();

let mut ok = true;
for (s, t) in st.iter() {
let count = x
.iter()
.copied()
.zip(s.iter().copied())
.filter(|(x_i, s_i)| x_i == s_i)
.count();
match t {
1 => {
if count != 4 {
ok = false;
}
}
2 => {
if count != 3 {
ok = false;
}
}
3 => {
if count >= 3 {
ok = false;
}
}
_ => unreachable!(),
}
}

if ok {
ans.push(x);
}
}

if ans.len() != 1 {
println!("Can't Solve");
return;
}

println!("{}", ans[0].iter().collect::<String>());
}

0 comments on commit 19d41dc

Please sign in to comment.