結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー pockynypockyny
提出日時 2021-07-09 21:45:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 175 ms / 2,000 ms
コード長 855 bytes
コンパイル時間 534 ms
コンパイル使用メモリ 69,304 KB
実行使用メモリ 13,028 KB
最終ジャッジ日時 2023-09-14 08:22:54
合計ジャッジ時間 3,910 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
12,784 KB
testcase_01 AC 14 ms
12,752 KB
testcase_02 AC 174 ms
12,988 KB
testcase_03 AC 174 ms
12,808 KB
testcase_04 AC 174 ms
13,028 KB
testcase_05 AC 172 ms
12,744 KB
testcase_06 AC 173 ms
12,780 KB
testcase_07 AC 175 ms
12,800 KB
testcase_08 AC 174 ms
12,708 KB
testcase_09 AC 175 ms
12,724 KB
testcase_10 AC 175 ms
12,800 KB
testcase_11 AC 146 ms
12,800 KB
testcase_12 AC 147 ms
12,856 KB
testcase_13 AC 147 ms
12,824 KB
testcase_14 AC 14 ms
12,708 KB
testcase_15 AC 13 ms
12,864 KB
testcase_16 AC 13 ms
12,708 KB
testcase_17 AC 14 ms
12,720 KB
testcase_18 AC 14 ms
12,712 KB
testcase_19 AC 13 ms
12,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

using namespace std;
using ll = long long;
const int MX = 400010;
ll f[MX],inv[MX],fi[MX];
constexpr ll mod = 1000000007;
void solve(){
    inv[1] = 1;
    for(int i=2;i<MX;i++){
        inv[i] = mod - (mod/i)*inv[mod%i]%mod;
    }
    f[0] = fi[0] = 1;
    for(int i=1;i<MX;i++){
        f[i] = f[i-1]*i%mod;
        fi[i] = fi[i-1]*inv[i]%mod;
    }
}

ll nck(ll n, ll k){
    if(n<0 || k<0 || n<k) return 0;
    return f[n]*fi[k]%mod*fi[n-k]%mod;
}

int main(){
    ll i,n,m; cin >> n >> m;
    solve();
    ll ans = 2*n*nck(2*n,n)%mod;
    for(i=0;i<m;i++){
        int t,x,y; cin >> t >> x >> y;
        if(t==1){
            (ans += mod - nck(x + y,y)*nck(2*n - x - y - 1,n - y)%mod) %= mod;
        }else{
            (ans += mod - nck(x + y,y)*nck(2*n - x - y - 1,n - x)%mod) %= mod;
        }
    }
    cout << ans << endl;
}
0