結果

問題 No.1623 三角形の制作
ユーザー fukafukatanifukafukatani
提出日時 2021-07-23 21:57:59
言語 Rust
(1.77.0)
結果
AC  
実行時間 411 ms / 2,000 ms
コード長 1,844 bytes
コンパイル時間 6,458 ms
コンパイル使用メモリ 153,108 KB
実行使用メモリ 288,276 KB
最終ジャッジ日時 2023-09-25 21:58:34
合計ジャッジ時間 14,862 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 374 ms
283,596 KB
testcase_01 AC 374 ms
283,584 KB
testcase_02 AC 393 ms
286,148 KB
testcase_03 AC 397 ms
286,048 KB
testcase_04 AC 396 ms
285,972 KB
testcase_05 AC 411 ms
288,160 KB
testcase_06 AC 376 ms
284,176 KB
testcase_07 AC 395 ms
286,016 KB
testcase_08 AC 378 ms
284,160 KB
testcase_09 AC 392 ms
285,808 KB
testcase_10 AC 404 ms
287,344 KB
testcase_11 AC 397 ms
286,552 KB
testcase_12 AC 379 ms
285,004 KB
testcase_13 AC 380 ms
285,536 KB
testcase_14 AC 379 ms
285,304 KB
testcase_15 AC 392 ms
288,124 KB
testcase_16 AC 394 ms
288,088 KB
testcase_17 AC 392 ms
288,128 KB
testcase_18 AC 399 ms
288,276 KB
testcase_19 AC 379 ms
286,304 KB
testcase_20 AC 375 ms
283,636 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `n`
  --> 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

warning: 1 warning emitted

ソースコード

diff #

#![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()
}
0