結果
問題 | No.1596 Distance Sum in 2D Plane |
ユーザー |
![]() |
提出日時 | 2021-07-09 21:58:06 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 223 ms / 2,000 ms |
コード長 | 1,224 bytes |
コンパイル時間 | 2,100 ms |
コンパイル使用メモリ | 197,864 KB |
最終ジャッジ日時 | 2025-01-22 21:40:38 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:47:9: warning: ‘tx’ may be used uninitialized [-Wmaybe-uninitialized] 47 | int x2 = n-tx; | ^~ main.cpp:38:9: note: ‘tx’ was declared here 38 | int tx,ty; | ^~ main.cpp:48:9: warning: ‘ty’ may be used uninitialized [-Wmaybe-uninitialized] 48 | int y2 = n-ty; | ^~ main.cpp:38:12: note: ‘ty’ was declared here 38 | int tx,ty; | ^~
ソースコード
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 long long mod_inv(long long n) { long long left = MOD-2; //define MOD long long ks = n; long long ans = 1; while (left != 0) { if (left%2 == 1) ans = ans*ks%MOD; left /= 2; ks = ks*ks%MOD; } return ans; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n,m; cin >> n >> m; vector<int> t(m),x(m),y(m); for (int i=0;i<m;i++) { cin >> t[i] >> x[i] >> y[i]; } vector<long long> fact(n*2+1,1); for (int i=2;i<=n*2;i++) { fact[i] = fact[i-1]*i%MOD; } long long ans = fact[2*n]*mod_inv(fact[n])%MOD*mod_inv(fact[n])%MOD; ans = ans*2*n%MOD; for (int i=0;i<m;i++) { int x1 = x[i]; int y1 = y[i]; int tx,ty; if (t[i] == 1) { tx = x[i]+1; ty = y[i]; } if (t[i] == 2) { tx = x[i]; ty = y[i]+1; } int x2 = n-tx; int y2 = n-ty; //cout << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << endl; long long r1 = fact[x1+y1]*mod_inv(fact[x1])%MOD*mod_inv(fact[y1])%MOD; long long r2 = fact[x2+y2]*mod_inv(fact[x2])%MOD*mod_inv(fact[y2])%MOD; long long rm = r1*r2%MOD; ans = (ans-rm+MOD)%MOD; } cout << ans << endl; }