Source Code
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int mod=1e9+7;
ll fact[200005];
ll modInverse(ll a, ll m)
{
    for (ll x = 1; x < m; x++)
        if (((a%m) * (x%m)) % m == 1)
            return x;
}
int main()
{
    fact[0]=1;
    for(int i=1; i<=2e5; i++)fact[i]=(fact[i-1]*i)%mod;
    ll n;
    ll cnt=0,x=1;
    cin>>n;
    vector<ll>p(n),q(n);
    for(auto&it:p)cin>>it;
    for(auto&it:q)cin>>it;
    for(int i=0; i<n; i++)
    {
        int num=abs(q[i]-p[i])/(i+1);
        cnt+=num;
        x*=fact[num];
        x%=mod;
    }
    cnt=fact[cnt];
   // cout<<cnt<<" "<<modInverse(cnt,x)<<" "<<x<<endl;
    cout<<(cnt/modInverse(cnt,x))%mod<<endl;
}
Copy
N-dimensions Amrharb
GNU G++17
3058 ms
1.7 MB
Time Limit Exceeded