結果
問題 | No.1596 Distance Sum in 2D Plane |
ユーザー |
![]() |
提出日時 | 2021-07-09 21:58:06 |
言語 | C++17 (gcc 11.2.0 + boost 1.78.0) |
結果 |
AC
|
実行時間 | 173 ms / 2,000 ms |
コード長 | 1,224 bytes |
コンパイル時間 | 1,832 ms |
使用メモリ | 8,632 KB |
最終ジャッジ日時 | 2023-02-01 23:20:06 |
合計ジャッジ時間 | 5,274 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 使用メモリ |
---|---|---|
testcase_00 | AC | 6 ms
6,340 KB |
testcase_01 | AC | 5 ms
6,268 KB |
testcase_02 | AC | 172 ms
8,604 KB |
testcase_03 | AC | 172 ms
8,520 KB |
testcase_04 | AC | 173 ms
8,628 KB |
testcase_05 | AC | 170 ms
8,564 KB |
testcase_06 | AC | 171 ms
8,520 KB |
testcase_07 | AC | 170 ms
8,524 KB |
testcase_08 | AC | 171 ms
8,528 KB |
testcase_09 | AC | 172 ms
8,608 KB |
testcase_10 | AC | 172 ms
8,536 KB |
testcase_11 | AC | 159 ms
8,632 KB |
testcase_12 | AC | 159 ms
8,628 KB |
testcase_13 | AC | 159 ms
8,528 KB |
testcase_14 | AC | 1 ms
3,484 KB |
testcase_15 | AC | 2 ms
3,524 KB |
testcase_16 | AC | 2 ms
3,392 KB |
testcase_17 | AC | 1 ms
3,456 KB |
testcase_18 | AC | 2 ms
3,536 KB |
testcase_19 | AC | 1 ms
3,520 KB |
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内: main.cpp:48:9: 警告: ‘ty’ はこの関数内初期化されずに使用されるかもしれません [-Wmaybe-uninitialized] 48 | int y2 = n-ty; | ^~ main.cpp:47:9: 警告: ‘tx’ はこの関数内初期化されずに使用されるかもしれません [-Wmaybe-uninitialized] 47 | int x2 = n-tx; | ^~
ソースコード
#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; }