Skip to content

Commit

Permalink
pastbook1 arc098 c
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed May 5, 2023
1 parent 708a7f5 commit adcc199
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion cargo-compete/pastbook1/src/bin/247.rs
@@ -1 +1,25 @@
fn main() { todo!(); }
use proconio::{input, marker::Chars};

fn main() {
input! {
n: usize,
s: Chars,
}

let mut count_w = vec![0; n];
for i in 0..n {
count_w[i] = if i > 0 { count_w[i - 1] } else { 0 } + if s[i] == 'W' { 1 } else { 0 };
}
let mut count_e = vec![0; n];
for i in 0..n {
count_e[i] =
if i > 0 { count_e[i - 1] } else { 0 } + if s[n - 1 - i] == 'E' { 1 } else { 0 };
}
count_e.reverse();

let mut min = n;
for i in 0..n {
min = min.min(count_e[i] + count_w[i] - 1);
}
println!("{}", min);
}

0 comments on commit adcc199

Please sign in to comment.