Skip to content

Commit 62436d9

Browse files
committed
add abc421c.rs
1 parent 75822aa commit 62436d9

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/abc/abc421c.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/** THIS IS AN OUTPUT FILE. NOT EDIT THIS FILE DIRECTLY. **/
2+
use proconio::input;
3+
use proconio::marker::*;
4+
use std::marker::PhantomData;
5+
use std::cmp::*;
6+
use std::collections::*;
7+
8+
fn main() {
9+
input! {
10+
n: usize,
11+
s: Chars,
12+
}
13+
14+
let mut indices = vec![];
15+
for i in 0..2*n {
16+
if s[i] == 'A' {
17+
indices.push(i);
18+
}
19+
}
20+
let mut diff1 = 0;
21+
for i in 0..n {
22+
diff1 += (2*i).abs_diff(indices[i]);
23+
}
24+
let mut diff2 = 0;
25+
for i in 0..n {
26+
diff2 += (2*i+1).abs_diff(indices[i]);
27+
}
28+
29+
println!("{}", min(diff1, diff2));
30+
}

0 commit comments

Comments
 (0)