結果

問題 No.1623 三角形の制作
ユーザー phsplsphspls
提出日時 2022-10-30 13:13:21
言語 Rust
(1.77.0)
結果
AC  
実行時間 321 ms / 2,000 ms
コード長 1,519 bytes
コンパイル時間 6,411 ms
コンパイル使用メモリ 142,176 KB
実行使用メモリ 150,496 KB
最終ジャッジ日時 2023-09-21 11:30:46
合計ジャッジ時間 10,022 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 218 ms
142,628 KB
testcase_01 AC 217 ms
142,636 KB
testcase_02 AC 310 ms
146,928 KB
testcase_03 AC 311 ms
146,828 KB
testcase_04 AC 312 ms
146,756 KB
testcase_05 AC 321 ms
149,944 KB
testcase_06 AC 302 ms
143,852 KB
testcase_07 AC 310 ms
146,864 KB
testcase_08 AC 299 ms
143,844 KB
testcase_09 AC 307 ms
146,624 KB
testcase_10 AC 316 ms
148,668 KB
testcase_11 AC 312 ms
147,372 KB
testcase_12 AC 223 ms
145,216 KB
testcase_13 AC 228 ms
145,588 KB
testcase_14 AC 221 ms
145,456 KB
testcase_15 AC 235 ms
149,800 KB
testcase_16 AC 234 ms
149,836 KB
testcase_17 AC 236 ms
149,840 KB
testcase_18 AC 239 ms
150,496 KB
testcase_19 AC 226 ms
146,128 KB
testcase_20 AC 218 ms
142,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

const LIMIT: 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 greens = vec![0usize; LIMIT+1];
    let mut blues = vec![0usize; LIMIT+1];
    for i in 0..n {
        greens[g[i]] += 1;
        blues[b[i]] += 1;
    }
    let mut maxsum = vec![vec![0usize; 2*LIMIT+1]; LIMIT+1];
    for i in 0..=LIMIT {
        if greens[i] == 0 { continue; }
        for j in 0..=LIMIT {
            let maxval = i.max(j);
            let sumval = i+j;
            maxsum[maxval][sumval] += greens[i] * blues[j];
        }
    }
    for i in 0..=LIMIT {
        for j in 0..=2*LIMIT {
            if i > 0 { maxsum[i][j] += maxsum[i-1][j]; }
            if j > 0 { maxsum[i][j] += maxsum[i][j-1]; }
            if i > 0 && j > 0 { maxsum[i][j] -= maxsum[i-1][j-1]; }
        }
    }
    let mut result = 0usize;
    for &v in r.iter() {
        result += maxsum[v][v*2] - maxsum[v][v];
    }
    println!("{}", result);
}
0