complete 25551.rs 26031.rs 34928.rs
This commit is contained in:
38
storage/zeta/rs/completed/25551.rs
Normal file
38
storage/zeta/rs/completed/25551.rs
Normal file
@@ -0,0 +1,38 @@
|
||||
use std::{
|
||||
cmp::min,
|
||||
io::{stdin, Read},
|
||||
};
|
||||
|
||||
fn main() {
|
||||
let mut line = String::new();
|
||||
stdin().read_to_string(&mut line).unwrap();
|
||||
let mut iter = line
|
||||
.trim()
|
||||
.split_ascii_whitespace()
|
||||
.map(|x| x.parse::<i64>().unwrap());
|
||||
|
||||
let (mw, mb, tw, tb, pw, pb) = {
|
||||
(
|
||||
iter.next().unwrap(),
|
||||
iter.next().unwrap(),
|
||||
iter.next().unwrap(),
|
||||
iter.next().unwrap(),
|
||||
iter.next().unwrap(),
|
||||
iter.next().unwrap(),
|
||||
)
|
||||
};
|
||||
|
||||
let s1 = min(tw, min(mb, pb));
|
||||
let s2 = min(tb, min(pw, mw));
|
||||
|
||||
|
||||
let res = if s1 == s2 {
|
||||
s1 + s2
|
||||
} else if s1 > s2 {
|
||||
2 * s2 + 1
|
||||
} else {
|
||||
2 * s1 + 1
|
||||
};
|
||||
|
||||
println!("{}", res);
|
||||
}
|
||||
54
storage/zeta/rs/completed/26031.rs
Normal file
54
storage/zeta/rs/completed/26031.rs
Normal file
@@ -0,0 +1,54 @@
|
||||
use std::cmp::max;
|
||||
use std::{io::stdin, usize};
|
||||
|
||||
#[allow(unused_assignments)]
|
||||
fn get_highest_peak(heights: &Vec<usize>) -> usize {
|
||||
let n = heights.len();
|
||||
let mut left_min = vec![0; n];
|
||||
let mut right_min = vec![0; n];
|
||||
|
||||
left_min[0] = heights[0];
|
||||
right_min[n - 1] = heights[n - 1];
|
||||
|
||||
for i in 1..n {
|
||||
if heights[i] < heights[i - 1] {
|
||||
left_min[i] = heights[i];
|
||||
} else {
|
||||
left_min[i] = left_min[i - 1];
|
||||
}
|
||||
}
|
||||
|
||||
for j in (0..(n - 1)).rev() {
|
||||
if heights[j] < heights[j + 1] {
|
||||
right_min[j] = heights[j];
|
||||
} else {
|
||||
right_min[j] = right_min[j + 1];
|
||||
}
|
||||
}
|
||||
|
||||
let mut max_peak = 0;
|
||||
|
||||
for i in 1..n - 1 {
|
||||
if heights[i] >= heights[i - 1] && heights[i] >= heights[i + 1] {
|
||||
let peak = heights[i] - max(left_min[i - 1], right_min[i + 1]);
|
||||
max_peak = max(max_peak, peak);
|
||||
}
|
||||
}
|
||||
max_peak
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut line = String::new();
|
||||
stdin().read_line(&mut line).unwrap();
|
||||
let _: usize = line.trim().parse().unwrap();
|
||||
|
||||
line.clear();
|
||||
stdin().read_line(&mut line).unwrap();
|
||||
let heights: Vec<usize> = line
|
||||
.trim()
|
||||
.split_ascii_whitespace()
|
||||
.map(|s| s.parse().unwrap())
|
||||
.collect();
|
||||
|
||||
println!("{}", get_highest_peak(&heights));
|
||||
}
|
||||
28
storage/zeta/rs/completed/34928.rs
Normal file
28
storage/zeta/rs/completed/34928.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
use std::io::stdin;
|
||||
|
||||
fn main() {
|
||||
let mut line = String::new();
|
||||
stdin().read_line(&mut line).unwrap();
|
||||
let mut iter = line.split(' ');
|
||||
let s = iter.next().unwrap().trim().to_string();
|
||||
let n = s.len();
|
||||
let mut represent = 0u64;
|
||||
for (i, c) in s.chars().enumerate() {
|
||||
if c == 'B' {
|
||||
represent |= 1 << i;
|
||||
}
|
||||
}
|
||||
|
||||
let day = iter.next().unwrap().trim().parse::<u64>().unwrap();
|
||||
|
||||
represent += day;
|
||||
represent %= 1 << n;
|
||||
|
||||
for i in 0..n {
|
||||
if (represent & (1 << i)) != 0 {
|
||||
print!("B");
|
||||
} else {
|
||||
print!("A");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user