QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#457310#8829. Aibohphobiaucup-team635#WA 0ms1992kbRust3.5kb2024-06-29 10:24:482024-06-29 10:24:49

Judging History

你现在查看的是最新测评结果

  • [2024-06-29 10:24:49]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:1992kb
  • [2024-06-29 10:24:48]
  • 提交

answer

use std::collections::*;
use std::io::Write;

type Map<K, V> = BTreeMap<K, V>;
type Set<T> = BTreeSet<T>;
type Deque<T> = VecDeque<T>;

fn run() {
    input! {
        t: usize,
        ask: [chars; t],
    }
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    for s in ask {
        let solve = || -> Option<Vec<char>> {
            let mut map = Map::new();
            for &s in s.iter() {
                *map.entry(s).or_insert(0) += 1;
            }
            if map.len() == 1 {
                return None;
            }
            if map.len() == 2 {
                let mut s = s;
                s.sort();
                for _ in 0..2 {
                    if s[0] != s[1] {
                        return Some(s);
                    }
                    s.reverse();
                }
                return None;
            }
            let mut ans = vec![];
            for c in map.keys() {
                ans.push(*c);
            }
            for (c, v) in map.iter() {
                for _ in 1..*v {
                    ans.push(*c);
                }
            }
            Some(ans)
        };
        if let Some(s) = solve() {
            use util::*;
            writeln!(out, "YES").ok();
            writeln!(out, "{}", s.iter().join("")).ok();
        } else {
            writeln!(out, "NO").ok();
        }
    }
}

fn main() {
    run();
}

// ---------- begin input macro ----------
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[macro_export]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[macro_export]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[macro_export]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, bytes) => {
        read_value!($iter, String).bytes().collect::<Vec<u8>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
// ---------- end input macro ----------
mod util {
    pub trait Join {
        fn join(self, sep: &str) -> String;
    }

    impl<T, I> Join for I
    where
        I: Iterator<Item = T>,
        T: std::fmt::Display,
    {
        fn join(self, sep: &str) -> String {
            let mut s = String::new();
            use std::fmt::*;
            for (i, v) in self.enumerate() {
                if i > 0 {
                    write!(&mut s, "{}", sep).ok();
                }
                write!(&mut s, "{}", v).ok();
            }
            s
        }
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 1992kb

input:

5
a
sos
abba
icpc
tenet

output:

NO
YES
oss
NO
YES
cipc
YES
entet

result:

wrong answer Jury found the answer but participant didn't (test case 1)