結果

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

ソースコード

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 = 5000;
        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