Source Code
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<cstring>
#include<sstream>
using namespace std;
long long mod=1000000007;
long long NpR(long long  n, long long  r){
    long long  ans = 1;
    for (long long  i = (n - r) + 1; i <= n; i++){
        ans *= i;
        ans %= mod;
    }
    return ans;
}
long long  nCr(long long  n, long long  r){
    long long ans = 1;
    long long  div = 1; // r!
    for (long long  i = r + 1; i <= n; i++){
        ans = ans * i;
        ans /= div;
        div++;
    }
    return ans;
}
int main() {
    std::ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n,o=0,ans=1;
    cin>>n;
    vector<long long >p(n+1),q(n+1);
    for(int i=1;i<=n;i++)
        cin>>p[i];
    for(int i=1;i<=n;i++)
    {
        cin>>q[i];
        o+=(q[i]-p[i])/i;
    }
    for(int i=1;i<=n;i++){
        if(p[i]!=q[i]){
            ans=((ans%mod)*(nCr(o,(q[i]-p[i])/i)%mod))%mod;
            o-=(q[i]-p[i])/i;
        }
    }
    cout<<ans;



}
Copy
N-dimensions AyaHamza
GNU G++17
3070 ms
3.4 MB
Time Limit Exceeded