結果
問題 | No.1785 Inequality Signs |
ユーザー |
![]() |
提出日時 | 2021-12-25 21:01:52 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,336 bytes |
コンパイル時間 | 1,558 ms |
コンパイル使用メモリ | 166,996 KB |
実行使用メモリ | 10,624 KB |
最終ジャッジ日時 | 2024-09-22 02:11:37 |
合計ジャッジ時間 | 5,538 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | TLE * 1 -- * 51 |
ソースコード
#include <bits/stdc++.h> using namespace std; int rev(int a,int mod){ long long temp[3]; temp[0]=a; temp[1]=mod-2; temp[2]=1; while(temp[1]){ if(temp[1]%2){ temp[2]*=temp[0]; temp[2]%=mod; } temp[0]*=temp[0]; temp[0]%=mod; temp[1]>>=1; } return (int)temp[2]; } int calc(int a,int b,int mod){ if(a>b){ swap(a,b); } long long ans=0,temp[5]; fill(temp,temp+4,1); for(int i=2;i<=a+b;++i){ temp[0]*=i; temp[0]%=mod; if(i<=a){ temp[2]*=i; temp[2]%=mod; } if(i<=b){ temp[3]*=i; temp[3]%=mod; } } for(int i=0;i<=a;++i){ temp[4]=temp[0]; for(int j=1;j<=3;++j){ temp[4]*=rev(temp[j],mod); temp[4]%=mod; } ans+=temp[4]; ans%=mod; temp[0]*=rev(a+b-i,mod); temp[0]%=mod; temp[1]*=i+1; temp[1]%=mod; temp[2]*=rev(a-i,mod); temp[2]%=mod; temp[3]*=rev(b-i,mod); temp[3]%=mod; } return (int)ans; } int main(){ int a,b,mod=1e9+7; long long ans=mod; scanf("%d%d",&a,&b); ans+=calc(a,b,mod); ans-=calc(a-1,b,mod); ans*=(mod/2+1); ans%=mod; printf("%d\n",ans); }