結果
問題 | No.1596 Distance Sum in 2D Plane |
ユーザー |
![]() |
提出日時 | 2021-07-09 21:58:06 |
言語 | C++17 (gcc 12.2.0 + boost 1.81.0) |
結果 |
AC
|
実行時間 | 174 ms / 2,000 ms |
コード長 | 1,224 bytes |
コンパイル時間 | 2,017 ms |
コンパイル使用メモリ | 203,032 KB |
実行使用メモリ | 8,624 KB |
最終ジャッジ日時 | 2023-09-14 08:56:17 |
合計ジャッジ時間 | 5,485 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 5 ms
6,196 KB |
testcase_01 | AC | 4 ms
6,084 KB |
testcase_02 | AC | 174 ms
8,572 KB |
testcase_03 | AC | 170 ms
8,508 KB |
testcase_04 | AC | 172 ms
8,564 KB |
testcase_05 | AC | 171 ms
8,512 KB |
testcase_06 | AC | 166 ms
8,564 KB |
testcase_07 | AC | 174 ms
8,516 KB |
testcase_08 | AC | 172 ms
8,436 KB |
testcase_09 | AC | 174 ms
8,532 KB |
testcase_10 | AC | 172 ms
8,624 KB |
testcase_11 | AC | 163 ms
8,516 KB |
testcase_12 | AC | 162 ms
8,444 KB |
testcase_13 | AC | 158 ms
8,620 KB |
testcase_14 | AC | 1 ms
4,380 KB |
testcase_15 | AC | 2 ms
4,376 KB |
testcase_16 | AC | 2 ms
4,380 KB |
testcase_17 | AC | 1 ms
4,376 KB |
testcase_18 | AC | 2 ms
4,376 KB |
testcase_19 | AC | 1 ms
4,380 KB |
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内: main.cpp:48:9: 警告: ‘ty’ may be used uninitialized [-Wmaybe-uninitialized] 48 | int y2 = n-ty; | ^~ main.cpp:38:12: 備考: ‘ty’ はここで定義されています 38 | int tx,ty; | ^~ main.cpp:47:9: 警告: ‘tx’ may be used uninitialized [-Wmaybe-uninitialized] 47 | int x2 = n-tx; | ^~ main.cpp:38:9: 備考: ‘tx’ はここで定義されています 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; }