Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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!(), | ||
} | ||
} | ||
} |