提出 #73588785


ソースコード 拡げる

pub mod lib {
    lazy_static! {
        pub static ref SEMVER: Regex = Regex::new(r#""#).expect("error parsing regex");
    }

    pub use external_lib::*;
    pub use my_lib::*;

    pub mod external_lib {
        pub use ac_library::{
            FenwickTree, LazySegtree, MapMonoid, MfGraph, ModInt as Mint, Monoid, Segtree,
        };
        pub use itertools::{Itertools, chain};
        pub use lazy_static::lazy_static;
        pub use memoise::*;
        pub use multimap::MultiMap;
        pub use num::{
            BigInt,
            integer::{ExtendedGcd, Integer, gcd},
        };
        pub use ordered_float::NotNan;
        pub use petgraph::unionfind::UnionFind;
        pub use proconio::{
            fastout, input,
            marker::{Bytes, Chars, Isize1, Usize1},
        };
        pub use regex::Regex;
        pub use std::{
            cmp::{Reverse, max, min},
            collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque},
            f64::consts::PI,
            iter::{empty, from_fn, once, repeat, repeat_n, repeat_with, successors, zip},
            mem::{swap, take},
        };
        pub use superslice::Ext;
    }
    pub mod my_lib {
        pub use combinations::*;
        pub use helpful::*;
        pub use macros::*;
        pub use setup::*;
        pub use vec2::*;

        pub mod combinations {
            #[inline]
            pub fn factorial(n: usize) -> usize {
                (1..=n).product::<usize>()
            }
            #[inline]
            pub fn permutation(n: usize, r: usize) -> usize {
                if n < r {
                    0
                } else {
                    (n - r + 1..=n).product::<usize>()
                }
            }
            /// これを何度も使いたい時は階乗を前計算するようなプログラムを作ることを推奨
            #[inline]
            pub fn combination(n: usize, r: usize) -> usize {
                if n < r {
                    0
                } else {
                    permutation(n, r) / factorial(r)
                }
            }
            #[inline]
            pub fn homogeneous(n: usize, r: usize) -> usize {
                combination(n + r - 1, r)
            }
        }
        pub mod helpful {
            use std::{iter::from_fn, ops::DivAssign};

            use easy_ext::ext;
            use num::Integer;

            #[ext(VecCharToString)]
            pub impl<'a, T: 'a> Vec<T>
            where
                String: FromIterator<&'a T>,
            {
                fn to_string(&'a self) -> String {
                    self.iter().collect::<String>()
                }
            }

            #[ext(Digits)]
            pub impl<N: Integer + DivAssign + Copy + 'a, 'a> N {
                fn digits(mut self, a: N) -> impl Iterator<Item = N> {
                    from_fn(move || {
                        (!self.is_zero()).then(|| {
                            let t = self % a;
                            self /= a;
                            t
                        })
                    })
                }
            }

            pub fn factorization(mut n: usize) -> Vec<(usize, usize)> {
                let mut v = vec![];
                for c in 2..=n.isqrt() {
                    let mut i = 0;
                    while n % c == 0 {
                        n /= c;
                        i += 1;
                    }
                    if i != 0 {
                        v.push((c, i));
                    }
                    if n == 1 {
                        return v;
                    }
                }
                if n != 1 {
                    v.push((n, 1));
                }
                v
            }
        }
        pub mod macros {
            use std::{borrow::Cow, collections::VecDeque, fmt::Display};

            use ac_library::ModInt;
            use itertools::{Format, Itertools};

            pub trait AtcoderOutput {
                fn ac_output(&'_ self) -> Cow<'_, str>;
            }

            impl AtcoderOutput for bool {
                fn ac_output(&'_ self) -> Cow<'_, str> {
                    Cow::Borrowed(if *self { "Yes" } else { "No" })
                }
            }
            impl<T: Display> AtcoderOutput for Option<T> {
                fn ac_output(&'_ self) -> Cow<'_, str> {
                    if let Some(a) = self {
                        Cow::Owned(format!("{a}"))
                    } else {
                        Cow::Borrowed("-1")
                    }
                }
            }
            impl<T: Display, E> AtcoderOutput for Result<T, E> {
                fn ac_output(&'_ self) -> Cow<'_, str> {
                    if let Ok(a) = self {
                        Cow::Owned(format!("{a}"))
                    } else {
                        Cow::Borrowed("-1")
                    }
                }
            }
            impl<T: Display> AtcoderOutput for Vec<T> {
                fn ac_output(&'_ self) -> Cow<'_, str> {
                    Cow::Owned(self.iter().format(" ").to_string())
                }
            }
            impl<T: Display> AtcoderOutput for VecDeque<T> {
                fn ac_output(&'_ self) -> Cow<'_, str> {
                    Cow::Owned(self.iter().format(" ").to_string())
                }
            }
            impl<T> AtcoderOutput for Format<'_, T>
            where
                for<'a> Format<'a, T>: ToString,
            {
                fn ac_output(&'_ self) -> Cow<'_, str> {
                    Cow::Owned(self.to_string())
                }
            }
            macro_rules! ans_impl {
                ($t: ident, $($u: ident),+) => {
                    ans_impl!($t);
                    ans_impl!($($u),+);
                };
                ($t:ident) => {
                    impl AtcoderOutput for $t {
                        fn ac_output(&'_ self) -> Cow<'_, str> {
                            Cow::Owned(format!("{}", self))
                        }
                    }
                }
            }
            ans_impl!(
                u8, i8, u16, i16, u32, i32, u64, i64, u128, i128, usize, isize, f32, f64, String,
                str, char, ModInt
            );

            #[macro_export]
            macro_rules! ans {
                ($v: expr, $($x: expr),+) => {{
                    ans!($v);
                    ans!($($x),+)
                }
                };
                (yes) => {
                    yes!()
                };
                (no) => {
                    no!()
                };
                ($output: expr) => {
                    println!("{}", $output.ac_output())
                };
                () => {{}}
            }

            #[macro_export]
            macro_rules! yes {
                () => {
                    println!("Yes")
                };
            }

            #[macro_export]
            macro_rules! no {
                () => {
                    println!("No")
                };
            }

            #[macro_export]
            macro_rules! chmax {
                ($var: expr; $($x: expr),+) => {{
                    let x = $crate::max!($($x),+);
                    if $var < x {
                        $var = x;
                        true
                    } else {
                        false
                    }
                }};
            }

            #[macro_export]
            macro_rules! chmin {
                ($var: expr; $($x: expr),+) => {{
                    let x = $crate::min!($($x),+);
                    if $var > x {
                        $var = x;
                        true
                    } else {
                        false
                    }
                }};
            }

            #[macro_export]
            macro_rules! max {
                ($($t: expr),+) => {[$($t),+].into_iter().max().unwrap()};
            }

            #[macro_export]
            macro_rules! min {
                ($($t: expr),+) => {[$($t),+].into_iter().min().unwrap()};
            }

            #[macro_export]
            macro_rules! flat_max {
                ($($t: expr),+) => {[$($t),+].into_iter().flatten().max()};
            }

            #[macro_export]
            macro_rules! flat_min {
                ($($t: expr),+) => {[$($t),+].into_iter().flatten().min()};
            }

            #[macro_export]
            macro_rules! range_2d {
                ($tuple: expr) => {
                    range_2d!((0, 0), $tuple)
                };
                ($v: expr, $w: expr) => {
                    ($v.0..$w.0).flat_map(|a| ($v.1..$w.1).map(move |b| (a, b)))
                };
            }

            #[macro_export]
            macro_rules! nest {
                ($identify: expr; $dim1: expr, $($dim2: expr),+) => {
                    nest![nest![$identify; $($dim2),+]; $dim1]
                };
                ($identify: expr; $dim: expr) => {
                    vec![$identify; $dim]
                }
            }
        }
        pub mod setup {
            use std::iter::once;

            /// エラトステネスの篩
            pub fn eratosthenes(end: usize) -> Vec<usize> {
                let mut table = vec![true; end - 1];
                let mut ans = vec![];
                assert!(end > 1);
                for i in 2..=end {
                    if table[i - 2] {
                        for j in i..=end / i {
                            table[j * i - 2] = false;
                        }
                        ans.push(i);
                    }
                }
                ans
            }

            /// インテレータを受け取って累積和、\[0\]は区間和の計算用にT::default()
            pub fn cumulative_sum<
                T: std::ops::AddAssign + Default + Copy,
                I: IntoIterator<Item = T>,
            >(
                v: I,
            ) -> Vec<T> {
                once(T::default())
                    .chain(v.into_iter().scan(T::default(), |prev, s| {
                        *prev += s;
                        Some(*prev)
                    }))
                    .collect()
            }

            pub fn build_graph_undirected(
                n: usize,
                v: impl IntoIterator<Item = (usize, usize)>,
            ) -> Vec<Vec<usize>> {
                let mut nv = vec![vec![]; n];
                for (i, j) in v {
                    nv[i].push(j);
                    nv[j].push(i);
                }
                nv
            }

            pub fn build_graph_directed(
                n: usize,
                v: impl IntoIterator<Item = (usize, usize)>,
            ) -> Vec<Vec<usize>> {
                let mut nv = vec![vec![]; n];
                for (i, j) in v {
                    nv[i].push(j);
                }
                nv
            }

            pub fn build_graph_with_cost_undirected<T: Clone>(
                n: usize,
                v: impl IntoIterator<Item = (usize, usize, T)>,
            ) -> Vec<Vec<(usize, T)>> {
                let mut nv = vec![vec![]; n];
                for (i, j, w) in v {
                    nv[i].push((j, w.clone()));
                    nv[j].push((i, w.clone()));
                }
                nv
            }

            pub fn build_graph_with_cost_directed<T: Clone>(
                n: usize,
                v: impl IntoIterator<Item = (usize, usize, T)>,
            ) -> Vec<Vec<(usize, T)>> {
                let mut nv = vec![vec![]; n];
                for (i, j, w) in v {
                    nv[i].push((j, w.clone()));
                }
                nv
            }
        }
        pub mod vec2 {
            use easy_ext::ext;

            use crate::range_2d;

            /// 二次元Vecを時計回りに回転
            #[ext(Rotate)]
            impl<T: Copy> Vec<Vec<T>> {
                pub fn rotate_vec(&self) -> Self {
                    if self.is_empty() {
                        return vec![];
                    }
                    (0..self[0].len())
                        .map(|i| (0..self.len()).map(|j| self[j][i]).collect())
                        .collect()
                }
            }
            /// 二次元Vecを転置
            #[ext(TransposeVec)]
            impl<T: Copy> Vec<Vec<T>> {
                pub fn transpose_vec(&self) -> Self {
                    if self.is_empty() {
                        return vec![];
                    }
                    let n = self[0].len();
                    (0..n)
                        .map(|i| (0..self.len()).map(|j| self[j][i]).collect::<Vec<T>>())
                        .collect()
                }
            }
            /// 評価関数f()で有効範囲のみを残す
            #[ext(TrimBy)]
            impl<T: PartialEq + Copy> Vec<Vec<T>> {
                pub fn trim_by<F: Fn(T) -> bool + Copy>(&self, f: F) -> ((usize, usize), Self) {
                    if let Some((upper, _)) = self
                        .iter()
                        .enumerate()
                        .find(|(_, a)| a.iter().any(|a| f(*a)))
                    {
                        let lower = self
                            .iter()
                            .enumerate()
                            .rev()
                            .find(|(_, a)| a.iter().any(|a| f(*a)))
                            .unwrap()
                            .0;
                        let new = self[upper..=lower].to_vec().transpose_vec();
                        let left = new
                            .iter()
                            .enumerate()
                            .find(|(_, a)| a.iter().any(|a| f(*a)))
                            .unwrap()
                            .0;
                        let right = new
                            .iter()
                            .enumerate()
                            .rev()
                            .find(|(_, a)| a.iter().any(|a| f(*a)))
                            .unwrap()
                            .0;
                        ((upper, left), new[left..=right].to_vec().transpose_vec())
                    } else {
                        ((0, 0), vec![vec![]])
                    }
                }
            }

            #[ext(FindAll)]
            impl<T: PartialEq> Vec<Vec<T>> {
                pub fn find_all(&self, p: T) -> impl Iterator<Item = (usize, usize)> {
                    range_2d!((self.len(), self.first().unwrap_or(&vec![]).len()))
                        .filter(move |&v| self[v.0][v.1] == p)
                }
            }
        }
    }
}

use lib::*;

#[fastout]
fn main() {
    input! {
        n: usize,
        k: usize,
        m: usize,
        mut a: [(u8, usize); n]
    }
    let b = a
        .extract_if(.., |a| a.0 == 1)
        .map(|a| a.1)
        .k_largest(m)
        .collect_vec();
    let a = a.into_iter().map(|a| a.1).k_largest(k - m).collect_vec();
    if a.len() == k - m && b.len() == m {
        ans!(b.iter().sum::<usize>() + a.iter().sum::<usize>())
    } else {
        ans!(-1)
    }
}

提出情報

提出日時
問題 C - チーム編成
ユーザ toshikoshi_ramen
言語 Rust (rustc 1.89.0)
得点 300
コード長 15714 Byte
結果 AC
実行時間 35 ms
メモリ 6828 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果
AC × 3
AC × 87
セット名 テストケース
Sample sample01.txt, sample02.txt, sample03.txt
All sample01.txt, sample02.txt, sample03.txt, in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in30.txt, in31.txt, in32.txt, in33.txt, in34.txt, in35.txt, in36.txt, in37.txt, in38.txt, in39.txt, in40.txt, in41.txt, in42.txt, in43.txt, in44.txt, in45.txt, in46.txt, in47.txt, in48.txt, in49.txt, in50.txt, in51.txt, in52.txt, in53.txt, in54.txt, in55.txt, in56.txt, in57.txt, in58.txt, in59.txt, in60.txt, in61.txt, in62.txt, in63.txt, in64.txt, in65.txt, in66.txt, in67.txt, in68.txt, in69.txt, in70.txt, in71.txt, in72.txt, in73.txt, in74.txt, in75.txt, in76.txt, in77.txt, in78.txt, in79.txt, in80.txt, in81.txt, in82.txt, in83.txt, in84.txt
ケース名 結果 実行時間 メモリ
in01.txt AC 0 ms 2040 KiB
in02.txt AC 0 ms 2120 KiB
in03.txt AC 0 ms 1988 KiB
in04.txt AC 1 ms 2152 KiB
in05.txt AC 0 ms 1996 KiB
in06.txt AC 0 ms 2128 KiB
in07.txt AC 0 ms 2092 KiB
in08.txt AC 0 ms 2072 KiB
in09.txt AC 30 ms 5924 KiB
in10.txt AC 0 ms 1948 KiB
in11.txt AC 32 ms 6340 KiB
in12.txt AC 23 ms 5304 KiB
in13.txt AC 16 ms 5164 KiB
in14.txt AC 16 ms 5020 KiB
in15.txt AC 34 ms 6828 KiB
in16.txt AC 17 ms 6720 KiB
in17.txt AC 1 ms 2084 KiB
in18.txt AC 1 ms 2088 KiB
in19.txt AC 25 ms 5824 KiB
in20.txt AC 27 ms 5916 KiB
in21.txt AC 30 ms 5992 KiB
in22.txt AC 18 ms 6648 KiB
in23.txt AC 18 ms 5908 KiB
in24.txt AC 24 ms 5924 KiB
in25.txt AC 19 ms 5932 KiB
in26.txt AC 19 ms 5924 KiB
in27.txt AC 34 ms 6716 KiB
in28.txt AC 35 ms 6572 KiB
in29.txt AC 35 ms 6716 KiB
in30.txt AC 25 ms 5564 KiB
in31.txt AC 1 ms 2056 KiB
in32.txt AC 1 ms 1960 KiB
in33.txt AC 1 ms 1996 KiB
in34.txt AC 0 ms 2016 KiB
in35.txt AC 0 ms 1804 KiB
in36.txt AC 0 ms 2116 KiB
in37.txt AC 1 ms 2116 KiB
in38.txt AC 0 ms 2156 KiB
in39.txt AC 0 ms 2040 KiB
in40.txt AC 0 ms 1988 KiB
in41.txt AC 1 ms 1976 KiB
in42.txt AC 0 ms 1948 KiB
in43.txt AC 0 ms 1964 KiB
in44.txt AC 0 ms 1996 KiB
in45.txt AC 1 ms 2004 KiB
in46.txt AC 1 ms 1868 KiB
in47.txt AC 27 ms 6700 KiB
in48.txt AC 12 ms 4312 KiB
in49.txt AC 28 ms 5892 KiB
in50.txt AC 28 ms 5908 KiB
in51.txt AC 16 ms 4980 KiB
in52.txt AC 12 ms 4324 KiB
in53.txt AC 29 ms 5924 KiB
in54.txt AC 33 ms 6248 KiB
in55.txt AC 30 ms 5964 KiB
in56.txt AC 23 ms 4900 KiB
in57.txt AC 34 ms 6716 KiB
in58.txt AC 34 ms 6724 KiB
in59.txt AC 30 ms 5984 KiB
in60.txt AC 33 ms 6268 KiB
in61.txt AC 0 ms 2132 KiB
in62.txt AC 0 ms 1924 KiB
in63.txt AC 33 ms 6324 KiB
in64.txt AC 35 ms 6656 KiB
in65.txt AC 30 ms 5928 KiB
in66.txt AC 33 ms 6340 KiB
in67.txt AC 1 ms 2088 KiB
in68.txt AC 1 ms 2064 KiB
in69.txt AC 0 ms 2072 KiB
in70.txt AC 0 ms 2124 KiB
in71.txt AC 0 ms 1952 KiB
in72.txt AC 0 ms 1932 KiB
in73.txt AC 0 ms 2072 KiB
in74.txt AC 0 ms 2196 KiB
in75.txt AC 0 ms 1940 KiB
in76.txt AC 1 ms 2164 KiB
in77.txt AC 1 ms 2136 KiB
in78.txt AC 0 ms 2136 KiB
in79.txt AC 1 ms 2016 KiB
in80.txt AC 17 ms 6684 KiB
in81.txt AC 17 ms 6668 KiB
in82.txt AC 1 ms 2064 KiB
in83.txt AC 1 ms 2156 KiB
in84.txt AC 34 ms 6644 KiB
sample01.txt AC 0 ms 2028 KiB
sample02.txt AC 1 ms 1932 KiB
sample03.txt AC 0 ms 1952 KiB