Submission #62299779


Source Code Expand

use std::cmp::Reverse;
use std::collections::{BTreeSet, BinaryHeap};
#[allow(unused_imports)]
use itertools::Itertools;
use proconio::input;

fn main() {
    input!{
        n: usize,
        k: usize,
        mut v: [[i64; n]; 3]
    }
    fn func(a: i64, b:i64, c:i64) -> i64 {
         a*b + b*c + c*a
    }
    for i in 0..3 {
        v[i].sort();
    }

    let mut seen = BTreeSet::new();
    let mut heap = BinaryHeap::new();

    let mut s = func(v[0][n-1],v[1][n-1], v[2][n-1]);

    let mut count = k;
    seen.insert(vec![n-1, n-1, n-1]);
    heap.push((s, vec![n-1, n-1, n-1]));

    while let Some((sum, vec)) = heap.pop() {
        count -= 1;
        if count == 0 {
            println!("{}", sum);
            return;
        }
        let mut new_v = vec;
        for i in 0..3 {
            if new_v[i] != 0 {
                new_v[i] -= 1;
                if seen.insert(new_v.clone()) {
                    heap.push((func(v[0][new_v[0]], v[1][new_v[1]], v[2][new_v[2]]), new_v.clone()));
                }
                new_v[i] += 1;
            }
        }
    }

}

pub trait Debuggable {
    fn debug_string(&self) -> String;
}

impl<T: std::fmt::Debug + std::fmt::Display> Debuggable for Vec<T> {
    fn debug_string(&self) -> String {
        use itertools::Itertools;
        use std::iter::repeat;
        if let Some(max_size) = self.iter()
            .enumerate()
            .map(|(i, x)| (format!("{:?}", x).len()).max(format!("{:?}", i).len()))
            .max() {
                let mut idx = String::from("idx |");   
                let mut val = String::from("val |");   
                for (i, xi) in self.iter().enumerate() {
                    idx.push_str(
                        &format!(" {:>w$} |", i, w=max_size)
                    );
                    val.push_str(
                        &format!(" {:>w$} |", xi, w=max_size)
                    );
                }

                format!("{}\n{}\n{}\n", idx, repeat('-').take(idx.len()).join(""), val)
            } else {
                format!("idx | \nval |\n")
            }
    }
}

impl<T: std::fmt::Debug + std::fmt::Display> Debuggable for std::collections::BTreeSet<T> {
    fn debug_string(&self) -> String {
        use itertools::Itertools;
        format!("{{ {} }}", self.iter().join(", "))
    }
}

impl<T, U> Debuggable for std::collections::BTreeMap<T, U> 
where T: std::fmt::Debug + std::fmt::Display, U: std::fmt::Debug + std::fmt::Display
{
    fn debug_string(&self) -> String {
        use itertools::Itertools;
        format!(
            "{{\n{}\n }}", self.iter()
                .map(|(k, v)| format!("{k} -> {v}, "))
                .join("\n")
        )
    }
}

// lg! マクロの定義
#[macro_export]
macro_rules! lg {
    ($val:expr) => {
        #[cfg(feature = "local")]
        {
            {
                use Debuggable;
                let val = &$val;
                eprintln!(
                    "[{}:{}] {} = \n{}",
                    file!(),
                    line!(),
                    stringify!($val),
                    val.debug_string()
                );
                val
            }
        }
    }
}
    

Submission Info

Submission Time
Task F - K-th Largest Triplet
User ardRiriy
Language Rust (rustc 1.70.0)
Score 500
Code Size 3190 Byte
Status AC
Exec Time 811 ms
Memory 153136 KiB

Compile Error

warning: unused import: `std::cmp::Reverse`
 --> src/main.rs:1:5
  |
1 | use std::cmp::Reverse;
  |     ^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: the item `Itertools` is imported redundantly
  --> src/main.rs:55:13
   |
4  | use itertools::Itertools;
   |     -------------------- the item `Itertools` is already imported here
...
55 |         use itertools::Itertools;
   |             ^^^^^^^^^^^^^^^^^^^^

warning: the item `Itertools` is imported redundantly
  --> src/main.rs:81:13
   |
4  | use itertools::Itertools;
   |     -------------------- the item `Itertools` is already imported here
...
81 |         use itertools::Itertools;
   |             ^^^^^^^^^^^^^^^^^^^^

warning: the item `Itertools` is imported redundantly
  --> src/main.rs:90:13
   |
4  | use itertools::Itertools;
   |     -------------------- the item `Itertools` is already imported here
...
90 |         use itertools::Itertools;
   |             ^^^^^^^^^^^^^^^^^^^^

warning: variable does not need to be mutable
  --> src/main.rs:23:9
   |
23 |     let mut s = func(v[0][n-1],v[1][n-1], v[2][n-1]);
   |         ----^
   |         |
   |         help: remove this `mut`
   |
   = note: `#[warn(unused_mut)]` on by default

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 61
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_test_00.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt, 01_test_27.txt, 01_test_28.txt, 01_test_29.txt, 01_test_30.txt, 01_test_31.txt, 01_test_32.txt, 01_test_33.txt, 01_test_34.txt, 01_test_35.txt, 01_test_36.txt, 01_test_37.txt, 01_test_38.txt, 01_test_39.txt, 01_test_40.txt, 01_test_41.txt, 01_test_42.txt, 01_test_43.txt, 01_test_44.txt, 01_test_45.txt, 01_test_46.txt, 01_test_47.txt, 01_test_48.txt, 01_test_49.txt, 01_test_50.txt, 01_test_51.txt, 01_test_52.txt, 01_test_53.txt, 01_test_54.txt, 01_test_55.txt, 01_test_56.txt, 01_test_57.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 1880 KiB
00_sample_01.txt AC 1 ms 1988 KiB
00_sample_02.txt AC 1 ms 2168 KiB
01_test_00.txt AC 1 ms 2052 KiB
01_test_01.txt AC 43 ms 7024 KiB
01_test_02.txt AC 234 ms 20844 KiB
01_test_03.txt AC 315 ms 27980 KiB
01_test_04.txt AC 622 ms 44404 KiB
01_test_05.txt AC 713 ms 47832 KiB
01_test_06.txt AC 738 ms 49548 KiB
01_test_07.txt AC 556 ms 40064 KiB
01_test_08.txt AC 779 ms 50716 KiB
01_test_09.txt AC 681 ms 47084 KiB
01_test_10.txt AC 760 ms 50936 KiB
01_test_11.txt AC 597 ms 109280 KiB
01_test_12.txt AC 617 ms 95844 KiB
01_test_13.txt AC 444 ms 126976 KiB
01_test_14.txt AC 444 ms 141748 KiB
01_test_15.txt AC 646 ms 123876 KiB
01_test_16.txt AC 639 ms 123980 KiB
01_test_17.txt AC 563 ms 120700 KiB
01_test_18.txt AC 746 ms 122876 KiB
01_test_19.txt AC 755 ms 123084 KiB
01_test_20.txt AC 757 ms 123168 KiB
01_test_21.txt AC 811 ms 112268 KiB
01_test_22.txt AC 793 ms 123016 KiB
01_test_23.txt AC 687 ms 53524 KiB
01_test_24.txt AC 688 ms 53736 KiB
01_test_25.txt AC 478 ms 128692 KiB
01_test_26.txt AC 485 ms 132676 KiB
01_test_27.txt AC 455 ms 152760 KiB
01_test_28.txt AC 456 ms 152784 KiB
01_test_29.txt AC 466 ms 152920 KiB
01_test_30.txt AC 463 ms 152956 KiB
01_test_31.txt AC 507 ms 152620 KiB
01_test_32.txt AC 459 ms 152632 KiB
01_test_33.txt AC 462 ms 152888 KiB
01_test_34.txt AC 460 ms 152972 KiB
01_test_35.txt AC 526 ms 152896 KiB
01_test_36.txt AC 521 ms 152976 KiB
01_test_37.txt AC 522 ms 153088 KiB
01_test_38.txt AC 515 ms 153136 KiB
01_test_39.txt AC 510 ms 151380 KiB
01_test_40.txt AC 448 ms 151316 KiB
01_test_41.txt AC 435 ms 149744 KiB
01_test_42.txt AC 457 ms 151344 KiB
01_test_43.txt AC 509 ms 139884 KiB
01_test_44.txt AC 423 ms 139012 KiB
01_test_45.txt AC 390 ms 137128 KiB
01_test_46.txt AC 659 ms 149396 KiB
01_test_47.txt AC 63 ms 13044 KiB
01_test_48.txt AC 1 ms 1932 KiB
01_test_49.txt AC 577 ms 39912 KiB
01_test_50.txt AC 672 ms 53800 KiB
01_test_51.txt AC 640 ms 52392 KiB
01_test_52.txt AC 417 ms 116768 KiB
01_test_53.txt AC 434 ms 111656 KiB
01_test_54.txt AC 448 ms 124040 KiB
01_test_55.txt AC 169 ms 85580 KiB
01_test_56.txt AC 178 ms 85616 KiB
01_test_57.txt AC 186 ms 85672 KiB