結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー tentententen
提出日時 2021-07-12 15:09:21
言語 Java21
(openjdk 21)
結果
AC  
実行時間 452 ms / 2,000 ms
コード長 2,233 bytes
コンパイル時間 2,207 ms
コンパイル使用メモリ 74,368 KB
実行使用メモリ 72,732 KB
最終ジャッジ日時 2023-09-14 20:35:16
合計ジャッジ時間 9,734 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
59,476 KB
testcase_01 AC 76 ms
59,880 KB
testcase_02 AC 449 ms
72,212 KB
testcase_03 AC 445 ms
71,736 KB
testcase_04 AC 452 ms
71,948 KB
testcase_05 AC 438 ms
71,764 KB
testcase_06 AC 443 ms
71,632 KB
testcase_07 AC 441 ms
71,896 KB
testcase_08 AC 446 ms
72,024 KB
testcase_09 AC 434 ms
72,732 KB
testcase_10 AC 450 ms
71,936 KB
testcase_11 AC 390 ms
71,400 KB
testcase_12 AC 390 ms
71,464 KB
testcase_13 AC 396 ms
70,700 KB
testcase_14 AC 44 ms
49,460 KB
testcase_15 AC 44 ms
49,404 KB
testcase_16 AC 44 ms
49,408 KB
testcase_17 AC 44 ms
49,352 KB
testcase_18 AC 44 ms
49,368 KB
testcase_19 AC 44 ms
49,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        Combination cmb = new Combination(2 * n + 1);
        long ans = cmb.getComb(2 * n, n) * n * 2 % MOD;
        for (int i = 0; i < m; i++) {
            int type = sc.nextInt();
            int x = sc.nextInt();
            int y = sc.nextInt();
            long minus;
            if (type == 1) {
                minus = cmb.getComb(x + y, x) * cmb.getComb(n - x - 1 + n - y, n - y) % MOD;
            } else {
                minus = cmb.getComb(x + y, x) * cmb.getComb(n - x + n - y - 1, n - y - 1) % MOD;
            }
            ans += MOD - minus;
            ans %= MOD;
        }
        System.out.println(ans);
    }
    
}


class Combination {
    static final int MOD = 1000000007;
    long[] fac;
    long[] finv;
    long[] inv;
    
    public Combination (int size) {
        fac = new long [size];
        finv = new long [size];
        inv = new long [size];
        fac[0] = 1;
        fac[1] = 1;
        finv[0] = 1;
        finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < size; i++) {
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }
    
    
    public long getComb(int n, int k) {
        if (n < k || n < 0 || k < 0) {
            return 0;
        }
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
    
}


class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0