結果

問題 No.1623 三角形の制作
ユーザー phspls
提出日時 2022-11-06 15:43:28
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 401 ms / 2,000 ms
コード長 1,427 bytes
コンパイル時間 14,528 ms
コンパイル使用メモリ 401,152 KB
実行使用メモリ 150,400 KB
最終ジャッジ日時 2024-07-20 04:55:36
合計ジャッジ時間 24,564 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

const MAXVAL: usize = 3000;

fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    let n: usize = n.trim().parse().unwrap();
    let mut r = String::new();
    std::io::stdin().read_line(&mut r).ok();
    let r: Vec<usize> = r.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let mut g = String::new();
    std::io::stdin().read_line(&mut g).ok();
    let g: Vec<usize> = g.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let mut b = String::new();
    std::io::stdin().read_line(&mut b).ok();
    let b: Vec<usize> = b.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    
    let mut gcnt = vec![0usize; MAXVAL+1];
    let mut bcnt = vec![0usize; MAXVAL+1];
    for i in 0..n {
        gcnt[g[i]] += 1;
        bcnt[b[i]] += 1;
    }
    let mut sum2max = vec![vec![0usize; MAXVAL+1]; 2*MAXVAL+1];
    for g in 0..=MAXVAL {
        for b in 0..=MAXVAL {
            sum2max[g+b][g.max(b)] += gcnt[g] * bcnt[b];
        }
    }
    for i in 0..=2*MAXVAL {
        for j in 0..=MAXVAL {
            if i > 0 { sum2max[i][j] += sum2max[i-1][j]; }
            if j > 0 { sum2max[i][j] += sum2max[i][j-1]; }
            if i > 0 && j > 0 { sum2max[i][j] -= sum2max[i-1][j-1]; }
        }
    }
    let mut result = 0usize;
    for &v in r.iter() {
        result += sum2max[2*v][v] - sum2max[v][v];
    }
    println!("{}", result);
}
0