ABC 047, finished b and c

This commit is contained in:
2022-06-07 14:10:25 +02:00
parent f631e0bfdc
commit a2acadbf3e
2 changed files with 52 additions and 8 deletions

View File

@@ -1,17 +1,33 @@
use proconio::input;
use std::cmp::max;
use std::cmp::{min, max};
fn main() {
input!{
h: u32,
w: u32,
n: u32,
lines: [(u32, u32, u32); n],
h: i64,
w: i64,
n: i64,
lines: [(i64, i64, i64); n],
};
let mut corners = ((0, 0), (w, h));
let mut corners = ((0, 0), (h, w));
let result = max(0,(corners.1.0 - corners.0.0) * (corners.1.1 - corners.0.1));
for (x, y, a) in lines {
match a {
1 => (corners.0).0 = max((corners.0).0, x),
2 => (corners.1).0 = min((corners.1).0, x),
3 => (corners.0).1 = max((corners.0).1, y),
4 => (corners.1).1 = min((corners.1).1, y),
_ => (),
}
}
let result;
if (corners.1).0 - (corners.0).0 > 0 && (corners.1).1 - (corners.0).1 > 0 {
result = ((corners.1).0 - (corners.0).0) * ((corners.1).1 - (corners.0).1);
} else {
result = 0;
}
println!("{}", {result});
}

View File

@@ -1,5 +1,33 @@
use proconio::input;
fn main() {
todo!();
input!{
s: String,
};
let mut result = 0;
let mut white_segment;
let first = s.chars().next().unwrap();
if first == 'W' {
white_segment = true;
} else {
white_segment = false;
}
for c in s.chars() {
match c {
'W' => if !white_segment {
white_segment = true;
result += 1;
},
'B' => if white_segment {
result += 1;
white_segment = false;
},
_ => (),
}
}
println!("{}", result);
}