Submission #1769112
Source Code Expand
fn main() {
let (mut w, mut h) = get::tuple::<usize,usize>();
let ps = get::vals::<usize>(w);
let qs = get::vals::<usize>(h);
let ps = ps.into_iter().map(|p|(p,0)).collect::<Vec<_>>();
let qs = qs.into_iter().map(|q|(q,1)).collect::<Vec<_>>();
let mut pqs = ps.into_iter().chain(qs.into_iter()).collect::<Vec<_>>();
pqs.sort();
let mut ans: usize = 0;
for (x, d) in pqs {
match d {
0 => {ans += x*(h+1); w-=1},
1 => {ans += x*(w+1); h-=1},
_ => unreachable!()
}
}
println!("{}", ans)
}
#[allow(dead_code)]
mod get {
use std::io::*;
use std::str::*;
pub fn val<T: FromStr>() -> T {
let mut buf = String::new();
let s = stdin();
s.lock().read_line(&mut buf).ok();
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();
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();
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 list<T: FromStr>() -> Vec<T> {
let mut buf = String::new();
let s = stdin();
s.lock().read_line(&mut buf).ok();
buf.trim_right().split_whitespace().map(|t| t.parse::<T>().ok().unwrap()).collect()
}
pub fn lists<T: FromStr>(h: usize) -> Vec<Vec<T>> {
let mut mat: Vec<Vec<T>> = vec![];
for _ in 0 .. h {
mat.push(list());
}
mat
}
pub fn chars() -> Vec<char> {
let mut buf = String::new();
let s = stdin();
s.lock().read_line(&mut buf).ok();
buf.trim_right().chars().collect()
}
}
Submission Info
Submission Time |
|
Task |
C - Gr-idian MST |
User |
aimy |
Language |
Rust (1.15.1) |
Score |
500 |
Code Size |
2735 Byte |
Status |
AC |
Exec Time |
57 ms |
Memory |
11832 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
500 / 500 |
Status |
|
|
Set Name |
Test Cases |
Sample |
s1.txt, s2.txt |
All |
01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, s1.txt, s2.txt |
Case Name |
Status |
Exec Time |
Memory |
01.txt |
AC |
57 ms |
11832 KB |
02.txt |
AC |
56 ms |
11832 KB |
03.txt |
AC |
57 ms |
11832 KB |
04.txt |
AC |
57 ms |
11832 KB |
05.txt |
AC |
57 ms |
11832 KB |
06.txt |
AC |
57 ms |
11832 KB |
07.txt |
AC |
57 ms |
11832 KB |
08.txt |
AC |
57 ms |
11832 KB |
09.txt |
AC |
57 ms |
11832 KB |
10.txt |
AC |
57 ms |
11832 KB |
11.txt |
AC |
47 ms |
11832 KB |
12.txt |
AC |
47 ms |
11832 KB |
13.txt |
AC |
37 ms |
11832 KB |
14.txt |
AC |
55 ms |
11832 KB |
15.txt |
AC |
55 ms |
11832 KB |
16.txt |
AC |
28 ms |
8444 KB |
17.txt |
AC |
28 ms |
8444 KB |
18.txt |
AC |
28 ms |
8444 KB |
19.txt |
AC |
28 ms |
8444 KB |
20.txt |
AC |
31 ms |
11828 KB |
21.txt |
AC |
43 ms |
11832 KB |
22.txt |
AC |
43 ms |
11828 KB |
23.txt |
AC |
34 ms |
11828 KB |
24.txt |
AC |
36 ms |
11832 KB |
25.txt |
AC |
2 ms |
4352 KB |
26.txt |
AC |
2 ms |
4352 KB |
27.txt |
AC |
2 ms |
4352 KB |
28.txt |
AC |
2 ms |
4352 KB |
s1.txt |
AC |
2 ms |
4352 KB |
s2.txt |
AC |
2 ms |
4352 KB |