Skip to content

Commit 8e72232

Browse files
committed
add a wrong answer for abc409d.rs
1 parent 8e2c424 commit 8e72232

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

src/abc/abc409d.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
t:usize,
11+
}
12+
13+
for _ in 0..t {
14+
input! {
15+
n:usize,
16+
mut s:Chars,
17+
}
18+
19+
let mut memo = vec![-1;26];
20+
21+
let mut l = n-1;
22+
let mut r = n-1;
23+
for i in (0..n).rev() {
24+
let c = s[i] as usize - 'a' as usize;
25+
let ii = i as i64;
26+
memo[c] = memo[c].max(ii);
27+
28+
// 自分より大きい最小のindexを求める
29+
let mut min = n;
30+
for j in c+1..26 {
31+
if memo[j] != -1 {
32+
min = min.min(memo[j] as usize);
33+
}
34+
}
35+
36+
// 自分より小さい最大のindexを求める
37+
let mut max = -1;
38+
for j in (0..c).rev() {
39+
if memo[j] != -1 {
40+
max = memo[j];
41+
}
42+
}
43+
44+
if max == -1 {
45+
continue
46+
}
47+
l = i;
48+
49+
if min < max as usize && 1 < min {
50+
r = min;
51+
} else if (max as usize) < min {
52+
r = max as usize + 1;
53+
}
54+
}
55+
56+
if l != n - 1 {
57+
// println!("l: {}, r: {} s:{}", l, r, s.iter().collect::<String>());
58+
s.insert(r, s[l]);
59+
s.remove(l);
60+
}
61+
62+
println!("{}", s.iter().collect::<String>());
63+
}
64+
}

0 commit comments

Comments
 (0)