結果

問題 No.1623 三角形の制作
コンテスト
ユーザー gorugo30
提出日時 2021-05-05 23:36:53
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 883 ms / 2,000 ms
コード長 1,335 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,539 ms
コンパイル使用メモリ 82,068 KB
実行使用メモリ 390,944 KB
最終ジャッジ日時 2026-04-02 10:41:16
合計ジャッジ時間 19,819 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.util.*;

class Main{
    static int max(int x, int y){
        return x > y ? x : y;
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int M = 3000;
        int n = sc.nextInt();
        int Rcnt[] = new int[M + 1];
        int Gcnt[] = new int[M + 1];
        int Bcnt[] = new int[M + 1];
        int x;
        for (int i = 0; i < n; i++){
            x = sc.nextInt();
            Rcnt[x]++;
        }
        for (int i = 0; i < n; i++){
            x = sc.nextInt();
            Gcnt[x]++;
        }
        for (int i = 0; i < n; i++){
            x = sc.nextInt();
            Bcnt[x]++;
        }
        
        long C[][] = new long[M + 2][2 * M + 2];
        for (int i = 1; i <= M; i++){
            for (int j = 1; j <= M; j++){
                C[max(i, j) + 1][i + j + 1] += (long)Gcnt[i] * Bcnt[j];
            }
        }
        for (int i = 0; i < M + 1; i++){
            for (int j = 0; j < 2 * M + 1; j++){
                C[i + 1][j + 1] += C[i][j + 1] + C[i + 1][j] - C[i][j];
            }
        }
        long ans = 0;
        for (int i = 1; i <= M; i++){
            long tmp = C[i + 1][2 * M + 1] + C[1][i + 1] - C[i + 1][i + 1] - C[1][2 * M + 1];
            ans += (long)Rcnt[i] * tmp;
        }

        System.out.println(ans);
    }
}
0