結果

問題 No.1623 三角形の制作
ユーザー gorugo30
提出日時 2021-05-05 23:36:53
言語 Java
(openjdk 23)
結果
AC  
実行時間 1,536 ms / 2,000 ms
コード長 1,335 bytes
コンパイル時間 2,262 ms
コンパイル使用メモリ 77,004 KB
実行使用メモリ 243,960 KB
最終ジャッジ日時 2024-07-18 16:28:51
合計ジャッジ時間 30,272 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

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