Skip to content

Commit

Permalink
agc022 a
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Feb 25, 2023
1 parent 1ac8867 commit 6126aee
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions agc022/src/bin/a.rs
@@ -1,10 +1,33 @@
use proconio::{input, marker::Usize1};
use proconio::{input, marker::Chars};

fn main() {
input! {
n: usize,
a: [Usize1; n],
s: Chars,
};
let ans = n - a.len();
println!("{}", ans);
let mut used = vec![false; 26];
for c in s.iter().copied() {
used[(c as u8 - b'a') as usize] = true;
}

for (i, b) in used.iter().copied().enumerate() {
if !b {
print!("{}", s.into_iter().collect::<String>());
println!("{}", (i as u8 + b'a') as char);
return;
}
}

for (i, c) in s.iter().copied().enumerate().rev() {
for j in (c as u8) + 1..=b'z' {
if !used[(j - b'a') as usize] {
for k in 0..i {
print!("{}", s[k]);
}
println!("{}", j as char);
return;
}
}
used[(c as u8 - b'a') as usize] = false;
}
println!("-1");
}

0 comments on commit 6126aee

Please sign in to comment.