Submission #9984642


Source Code Expand

Copy
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

MOD = 10 ** 9 + 7

def cumprod(A, MOD = MOD):
    L = len(A); Lsq = int(L**.5+1)
    A = np.resize(A, Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        A[:,n] *= A[:,n-1]; A[:,n] %= MOD
    for n in range(1,Lsq):
        A[n] *= A[n-1,-1]; A[n] %= MOD
    return A.ravel()[:L]


def make_fact(U, MOD = MOD):
    x = np.arange(U, dtype = np.int64); x[0] = 1
    fact = cumprod(x, MOD)
    x = np.arange(U, 0, -1, dtype=np.int64); x[0] = pow(int(fact[-1]), MOD-2, MOD)
    fact_inv = cumprod(x, MOD)[::-1]
    fact.flags.writeable = False
    fact_inv.flags.writeable = False
    return fact,fact_inv

fact, fact_inv = make_fact(2 * 10**6 + 10)

def F(i,j):
    return fact[i+j+2] * fact_inv[i+1] % MOD * fact_inv[j+1] % MOD

a,b,c,d = map(int,read().split())

answer = F(c,d) - F(a-1,d) - F(c,b-1) + F(a-1,b-1)
answer %= MOD
print(answer)

Submission Info

Submission Time
Task F - Many Many Paths
User maspy
Language Python3 (3.4.3)
Score 600
Code Size 1021 Byte
Status
Exec Time 361 ms
Memory 90548 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 01.txt, 02.txt
All 600 / 600 01.txt, 02.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt
Case Name Status Exec Time Memory
01.txt 355 ms 90548 KB
02.txt 356 ms 90548 KB
10.txt 355 ms 90544 KB
11.txt 357 ms 90544 KB
12.txt 358 ms 90548 KB
13.txt 361 ms 90548 KB
14.txt 355 ms 90548 KB
15.txt 360 ms 90544 KB
16.txt 359 ms 90544 KB
17.txt 353 ms 90544 KB