Submission #1941622


Source Code Expand

#![allow(unused_imports, unused_macros, unknown_lints)]

use std::collections::*;
use std::f64::*;
use std::cmp::*;
use std::cmp::Ordering::*;

macro_rules! dump {($($e:expr), +) => {println!(concat!($(stringify!($e), " = {:?}\n"), +), $($e), +)}}
macro_rules! max {($e0:expr, $($e:expr), +) => {{let mut r = $e0; $(r = max(r, $e);)+ r}}}
macro_rules! min {($e0:expr, $($e:expr), +) => {{let mut r = $e0; $(r = min(r, $e);)+ r}}}
macro_rules! freq {($v:expr) => {{let mut h = HashMap::new(); for x in $v {*h.entry(x).or_insert(0) += 1} h}}}

fn main() {
  let (_,k) = get::tuple::<usize,usize>();
  let s = get::chars();
  
  let mut s_sorted = s.clone(); s_sorted.sort();
  let mut t = s.clone();
  
  let mut x = k;
  let mut i = 0;
  while x != 0 && i < k {
    if t[i] == s_sorted[i] {i+=1; continue}
    let js = t.iter().enumerate().skip(i+1).
             flat_map(|(j,&c)|if s_sorted[i]==c {Some(j)} else {None}).
             collect::<Vec<_>>();
    t.swap(i,js[0]);
    x -= 1
  }

  let ans = t.into_iter().collect::<String>();
  println!("{}", ans)
}

#[allow(dead_code)]
mod get {
  use std::io::*;
  use std::str::*;
  use std::process::*;

  pub fn val<T: FromStr>() -> T {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    if buf.is_empty() {println!("No input"); exit(0)}
    buf.trim_right().parse::<T>().ok().unwrap()
  }

  pub fn vals<T: FromStr>(n: usize) -> Vec<T> {
    let mut vec: Vec<T> = vec![];
    for _ in 0 .. n {
      vec.push(val());
    }
    vec
  }

  pub fn tuple<T1: FromStr, T2: FromStr>() -> (T1, T2) {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    if buf.is_empty() {println!("No input"); exit(0)}
    let mut it = buf.trim_right().split_whitespace();
    let x = it.next().unwrap().parse::<T1>().ok().unwrap();
    let y = it.next().unwrap().parse::<T2>().ok().unwrap();
    (x, y)
  }

  pub fn tuples<T1: FromStr, T2: FromStr>(n: usize) -> Vec<(T1, T2)> {
    let mut vec: Vec<(T1, T2)> = vec![];
    for _ in 0 .. n {
      vec.push(tuple());
    }
    vec
  }

  pub fn tuple3<T1: FromStr, T2: FromStr, T3: FromStr>() -> (T1, T2, T3) {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    if buf.is_empty() {println!("No input"); exit(0)}
    let mut it = buf.trim_right().split_whitespace();
    let x = it.next().unwrap().parse::<T1>().ok().unwrap();
    let y = it.next().unwrap().parse::<T2>().ok().unwrap();
    let z = it.next().unwrap().parse::<T3>().ok().unwrap();
    (x, y, z)
  }

  pub fn tuple3s<T1: FromStr, T2: FromStr, T3: FromStr>(n: usize) -> Vec<(T1, T2, T3)> {
    let mut vec: Vec<(T1, T2, T3)> = vec![];
    for _ in 0 .. n {
      vec.push(tuple3());
    }
    vec
  }

  pub fn vec<T: FromStr>() -> Vec<T> {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    if buf.is_empty() {println!("No input"); exit(0)}
    buf.trim_right().split_whitespace().map(|t| t.parse::<T>().ok().unwrap()).collect()
  }

  pub fn mat<T: FromStr>(h: usize) -> Vec<Vec<T>> {
    let mut mat = vec![];
    for _ in 0 .. h {
      mat.push(vec());
    }
    mat
  }

  pub fn chars() -> Vec<char> {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    if buf.is_empty() {println!("No input"); exit(0)}
    buf.trim_right().chars().collect()
  }
}

#[allow(dead_code)]
mod put {
  use std::string::*;

  pub fn vec<T: ToString>(vec: &Vec<T>, sep: &str) {
    let out = vec.iter().map(|e| e.to_string()).collect::<Vec<_>>().as_slice().join(sep);
    println!("{}", out);
  }

  pub fn mat<T: ToString>(mat: &Vec<Vec<T>>, sep: &str) {
    for v in mat {
      vec(v, sep);
    }
  }
}

Submission Info

Submission Time
Task C - 辞書式順序ふたたび
User aimy
Language Rust (1.15.1)
Score 0
Code Size 3899 Byte
Status WA
Exec Time 2 ms
Memory 4352 KB

Judge Result

Set Name All
Score / Max Score 0 / 100
Status
AC × 19
WA × 39
Set Name Test Cases
All hand_1_0.txt, hand_1_1.txt, hand_1_2.txt, hand_1_3.txt, hand_1_4.txt, hand_1_5.txt, hand_1_6.txt, hand_1_7.txt, hand_1_8.txt, hand_2_0.txt, hand_2_1.txt, hand_2_10.txt, hand_2_2.txt, hand_2_3.txt, hand_2_4.txt, hand_2_5.txt, hand_2_6.txt, hand_2_7.txt, hand_2_8.txt, hand_2_9.txt, hand_3_2.txt, hand_3_3.txt, hand_3_4.txt, hand_3_5.txt, hand_3_6.txt, hand_4_2.txt, hand_4_3.txt, hand_4_4.txt, hand_4_5.txt, hand_4_6.txt, random_1.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_2.txt, random_3.txt, random_4.txt, random_5.txt, random_6.txt, random_7.txt, random_8.txt, random_9.txt, sample_1.txt, sample_2.txt, sample_3.txt, sample_4.txt, small_1.txt, small_2.txt, small_3.txt, small_4.txt, small_5.txt, small_6.txt, small_7.txt, small_8.txt, small_9.txt
Case Name Status Exec Time Memory
hand_1_0.txt AC 2 ms 4352 KB
hand_1_1.txt WA 2 ms 4352 KB
hand_1_2.txt WA 2 ms 4352 KB
hand_1_3.txt WA 2 ms 4352 KB
hand_1_4.txt WA 2 ms 4352 KB
hand_1_5.txt WA 2 ms 4352 KB
hand_1_6.txt WA 2 ms 4352 KB
hand_1_7.txt AC 2 ms 4352 KB
hand_1_8.txt AC 2 ms 4352 KB
hand_2_0.txt AC 2 ms 4352 KB
hand_2_1.txt WA 2 ms 4352 KB
hand_2_10.txt AC 2 ms 4352 KB
hand_2_2.txt WA 2 ms 4352 KB
hand_2_3.txt WA 2 ms 4352 KB
hand_2_4.txt WA 2 ms 4352 KB
hand_2_5.txt WA 2 ms 4352 KB
hand_2_6.txt WA 2 ms 4352 KB
hand_2_7.txt WA 2 ms 4352 KB
hand_2_8.txt AC 2 ms 4352 KB
hand_2_9.txt AC 2 ms 4352 KB
hand_3_2.txt WA 2 ms 4352 KB
hand_3_3.txt WA 2 ms 4352 KB
hand_3_4.txt WA 2 ms 4352 KB
hand_3_5.txt WA 2 ms 4352 KB
hand_3_6.txt WA 2 ms 4352 KB
hand_4_2.txt WA 2 ms 4352 KB
hand_4_3.txt WA 2 ms 4352 KB
hand_4_4.txt WA 2 ms 4352 KB
hand_4_5.txt WA 2 ms 4352 KB
hand_4_6.txt WA 2 ms 4352 KB
random_1.txt WA 2 ms 4352 KB
random_10.txt WA 2 ms 4352 KB
random_11.txt WA 2 ms 4352 KB
random_12.txt WA 2 ms 4352 KB
random_13.txt WA 2 ms 4352 KB
random_14.txt WA 2 ms 4352 KB
random_15.txt WA 2 ms 4352 KB
random_2.txt WA 2 ms 4352 KB
random_3.txt WA 2 ms 4352 KB
random_4.txt WA 2 ms 4352 KB
random_5.txt AC 2 ms 4352 KB
random_6.txt WA 2 ms 4352 KB
random_7.txt WA 2 ms 4352 KB
random_8.txt WA 2 ms 4352 KB
random_9.txt WA 2 ms 4352 KB
sample_1.txt AC 2 ms 4352 KB
sample_2.txt AC 2 ms 4352 KB
sample_3.txt AC 2 ms 4352 KB
sample_4.txt AC 2 ms 4352 KB
small_1.txt AC 2 ms 4352 KB
small_2.txt AC 2 ms 4352 KB
small_3.txt AC 2 ms 4352 KB
small_4.txt WA 2 ms 4352 KB
small_5.txt AC 2 ms 4352 KB
small_6.txt AC 2 ms 4352 KB
small_7.txt WA 2 ms 4352 KB
small_8.txt AC 2 ms 4352 KB
small_9.txt AC 2 ms 4352 KB