Skip to content

Commit cd70dca

Browse files
committed
Solve C in abc150
1 parent 7ac2bb4 commit cd70dca

File tree

1 file changed

+4
-11
lines changed
  • atcoder/rust/abc150/src/bin

1 file changed

+4
-11
lines changed

atcoder/rust/abc150/src/bin/c.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,8 @@ fn main() {
1616
q: [usize; n],
1717
}
1818

19-
let mut p_i = 0;
20-
let mut q_i = 0;
21-
for (i, comb) in (1..n + 1).permutations(n).enumerate() {
22-
if comb.eq(&p) {
23-
p_i = i;
24-
}
25-
if comb.eq(&q) {
26-
q_i = i;
27-
}
28-
}
29-
println!("{}", (p_i as i64 - q_i as i64).abs());
19+
let perms = (1..=n).permutations(n).collect::<Vec<Vec<usize>>>();
20+
let a = perms.iter().position(|perm| perm.eq(&p)).unwrap() as i64;
21+
let b = perms.iter().position(|perm| perm.eq(&q)).unwrap() as i64;
22+
println!("{}", (a - b).abs());
3023
}

0 commit comments

Comments
 (0)