提出 #55819341


ソースコード 拡げる

#![allow(unused)]

fn main() {
    let inp = readv::<usize>();
    let (n, k) = (inp[0], inp[1]);
    let mut s = reads();
    s.sort();

    let mut ans = 0;
    loop {
        let any = s.windows(k).any(|w| (0..k).all(|i| w[i] == w[k - 1 - i]));
        if !any {
            ans += 1;
        }
        
        if next_permutation(&mut s).is_none() {
            break;
        }
    }

    println!("{}", ans);
}

fn next_permutation<T: Ord>(arr: &mut [T]) -> Option<()> {
    let k = arr.windows(2).rposition(|w| w[0] < w[1])?;
    let j = arr.iter().rposition(|a| a > &arr[k]).unwrap();
    arr.swap(k, j);
    arr[(k + 1)..].reverse();
    Some(())
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn readv<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_ascii_whitespace()
        .map(|t| t.parse().ok().unwrap())
        .collect()
}

fn reads() -> Vec<char> {
    read::<String>().chars().collect()
}

fn mapv<T, S, F: Fn(&T) -> S>(arr: &Vec<T>, f: F) -> Vec<S> {
    arr.iter().map(f).collect()
}

fn join<T: ToString>(arr: &[T], sep: &str) -> String {
    arr.iter()
        .map(|x| x.to_string())
        .collect::<Vec<String>>()
        .join(sep)
}

提出情報

提出日時
問題 C - Avoid K Palindrome 2
ユーザ amoshuangyc
言語 Rust (rustc 1.70.0)
得点 300
コード長 1357 Byte
結果 AC
実行時間 45 ms
メモリ 2084 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果
AC × 3
AC × 38
セット名 テストケース
Sample example_00.txt, example_01.txt, example_02.txt
All example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 1 ms 1924 KiB
example_01.txt AC 1 ms 1928 KiB
example_02.txt AC 6 ms 1920 KiB
hand_00.txt AC 0 ms 1880 KiB
hand_01.txt AC 0 ms 2000 KiB
hand_02.txt AC 45 ms 2084 KiB
hand_03.txt AC 19 ms 1848 KiB
hand_04.txt AC 1 ms 1924 KiB
hand_05.txt AC 2 ms 2072 KiB
hand_06.txt AC 2 ms 1796 KiB
random_00.txt AC 1 ms 1860 KiB
random_01.txt AC 1 ms 2068 KiB
random_02.txt AC 1 ms 1896 KiB
random_03.txt AC 1 ms 2060 KiB
random_04.txt AC 1 ms 1920 KiB
random_05.txt AC 1 ms 1804 KiB
random_06.txt AC 1 ms 1900 KiB
random_07.txt AC 1 ms 2072 KiB
random_08.txt AC 1 ms 1916 KiB
random_09.txt AC 1 ms 1924 KiB
random_10.txt AC 1 ms 1960 KiB
random_11.txt AC 3 ms 1780 KiB
random_12.txt AC 1 ms 1972 KiB
random_13.txt AC 1 ms 1900 KiB
random_14.txt AC 11 ms 1868 KiB
random_15.txt AC 2 ms 1860 KiB
random_16.txt AC 4 ms 1916 KiB
random_17.txt AC 11 ms 1904 KiB
random_18.txt AC 1 ms 1928 KiB
random_19.txt AC 1 ms 2076 KiB
random_20.txt AC 1 ms 1920 KiB
random_21.txt AC 1 ms 1852 KiB
random_22.txt AC 0 ms 2052 KiB
random_23.txt AC 1 ms 1860 KiB
random_24.txt AC 1 ms 1928 KiB
random_25.txt AC 0 ms 1876 KiB
random_26.txt AC 2 ms 1924 KiB
random_27.txt AC 2 ms 1924 KiB