結果
問題 | No.1623 三角形の制作 |
ユーザー |
![]() |
提出日時 | 2021-07-23 21:57:59 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 393 ms / 2,000 ms |
コード長 | 1,844 bytes |
コンパイル時間 | 24,314 ms |
コンパイル使用メモリ | 404,660 KB |
実行使用メモリ | 288,176 KB |
最終ジャッジ日時 | 2024-07-18 17:39:53 |
合計ジャッジ時間 | 22,859 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 19 |
コンパイルメッセージ
warning: unused variable: `n` --> src/main.rs:19:9 | 19 | let n = read::<usize>(); | ^ help: if this is intentional, prefix it with an underscore: `_n` | = note: `#[warn(unused_variables)]` on by default
ソースコード
#![allow(unused_imports)] use std::cmp::*; use std::collections::*; use std::io::Write; use std::ops::Bound::*; #[allow(unused_macros)] macro_rules! debug { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; } fn main() { let n = read::<usize>(); let mut r = read_vec::<usize>(); r.sort(); let g = read_vec::<usize>(); let b = read_vec::<usize>(); let g_count = count(&g); let b_count = count(&b); let mut gb_count = vec![vec![0; 6001]; 3001]; for gi in 0..3001 { for bi in 0..3001 { gb_count[gi][gi + bi] = g_count[gi] * b_count[bi]; } } let mut gb_from_left = vec![vec![0; 6001]; 3001]; for gi in 0..3001 { gb_from_left[gi][0] = gb_count[gi][0]; for gbi in 1..6001 { gb_from_left[gi][gbi] = gb_from_left[gi][gbi - 1] + gb_count[gi][gbi]; } } let r_count = count(&r); let mut ans = 0i64; for ri in 1..3001 { for gi in 1..=ri { let gbi_max = gi + ri; let gbi_min = ri; //debug!(ri, r_count[ri] * gb_from_left[gi][ci_max]); ans += r_count[ri] * (gb_from_left[gi][gbi_max] - gb_from_left[gi][gbi_min]); } } println!("{}", ans); } fn count(r: &Vec<usize>) -> Vec<i64> { let mut count = vec![0; 3001]; for &num in r { count[num] += 1; } count } 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 read_vec<T: std::str::FromStr>() -> Vec<T> { read::<String>() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() }