Source Code
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
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()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    fact[0]=1;
    for(int i=1; i<=2e5; i++)fact[i]=(fact[i-1]*i)%mod;
    int n;
    ll cnt=0,x=1;
    cin>>n;
    vector<int>p(n),q(n);
    map<int,int>mp;
    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
3059 ms
1.8 MB
Time Limit Exceeded