We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7ac2bb4 commit cd70dcaCopy full SHA for cd70dca
atcoder/rust/abc150/src/bin/c.rs
@@ -16,15 +16,8 @@ fn main() {
16
q: [usize; n],
17
}
18
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());
+ let perms = (1..=n).permutations(n).collect::<Vec<Vec<usize>>>();
+ let a = perms.iter().position(|perm| perm.eq(&p)).unwrap() as i64;
+ let b = perms.iter().position(|perm| perm.eq(&q)).unwrap() as i64;
+ println!("{}", (a - b).abs());
30
0 commit comments