Skip to content

Commit

Permalink
typical90 058, 060, 061
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Jun 9, 2021
1 parent 0681c7e commit b67740f
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 0 deletions.
11 changes: 11 additions & 0 deletions typical90/src/bin/057.rs
@@ -0,0 +1,11 @@
use proconio::input;
use proconio::marker::Usize1;

fn main() {
input! {
n: usize,
a: [Usize1; n],
};
let ans = n - a.len();
println!("{}", ans);
}
39 changes: 39 additions & 0 deletions typical90/src/bin/058.rs
@@ -0,0 +1,39 @@
use std::collections::BTreeSet;

use proconio::input;

fn main() {
input! {
n: usize,
k: usize,
};
let m = 100_000;
let mut v = vec![0; m + 1];
v[0] = n;
for i in 0..m {
let x = v[i];
let y = x
.to_string()
.bytes()
.fold(0, |acc, b| acc + (b - b'0') as usize);
let z = (x + y) % m;
v[i + 1] = z;
}

let mut set = BTreeSet::new();
let mut start = 0;
let mut cycle = 0;
for (i, &v_i) in v.iter().enumerate() {
if !set.insert(v_i) {
start = v.iter().position(|&v_j| v_j == v_i).unwrap();
cycle = i - start;
break;
}
}
let ans = if k < start {
v[k]
} else {
v[start + (k - start) % cycle]
};
println!("{}", ans);
}
11 changes: 11 additions & 0 deletions typical90/src/bin/059.rs
@@ -0,0 +1,11 @@
use proconio::input;
use proconio::marker::Usize1;

fn main() {
input! {
n: usize,
a: [Usize1; n],
};
let ans = n - a.len();
println!("{}", ans);
}
46 changes: 46 additions & 0 deletions typical90/src/bin/060.rs
@@ -0,0 +1,46 @@
use std::cmp;

use proconio::input;
use superslice::Ext;

fn lis_lens(a: &[i64]) -> Vec<usize> {
let mut lis = vec![];
let mut res = vec![];
for &a_i in a.iter() {
let j = lis.upper_bound(&(a_i - 1));
match j.cmp(&lis.len()) {
cmp::Ordering::Less => {
lis[j] = a_i;
}
cmp::Ordering::Equal => {
lis.push(a_i);
}
cmp::Ordering::Greater => unreachable!(),
}
res.push(j + 1);
}
res
}

fn main() {
input! {
n: usize,
mut a: [i64; n],
};

let l1 = lis_lens(&a);
a.reverse();
let mut l2 = lis_lens(&a);
l2.reverse();

let mut max = 0;
for k in 0..n {
// a[0..k] で最長の部分列の前半の長さ b1
let b1 = l1[k];
// a[k..n] で最長の部分列の後半の長さ b2
let b2 = l2[k];
max = cmp::max(max, b1 + b2 - 1);
}
let ans = max;
println!("{}", ans);
}
18 changes: 18 additions & 0 deletions typical90/src/bin/061.rs
@@ -0,0 +1,18 @@
use proconio::input;
use std::collections::VecDeque;

fn main() {
input! {
q: usize,
tx: [(usize, usize); q],
};
let mut deque = VecDeque::new();
for (t_i, x_i) in tx {
match t_i {
1 => deque.push_front(x_i),
2 => deque.push_back(x_i),
3 => println!("{}", deque[x_i - 1]),
_ => unreachable!(),
}
}
}

0 comments on commit b67740f

Please sign in to comment.