AtCoder Beginner Contest 003

Submission #6902988

Source codeソースコード

#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    def comb(a,b):
        if b > a:
            return 0
        return fact[a]*inv[b]*inv[a-b]%mod
    def f(x,y):
        return comb(x*y,k)
    w,h = LI()
    x,y = LI()
    d,l = LI()
    fact = [1]
    for i in range(10000):
        fact.append(fact[-1]*(i+1)%mod)
    inv = [1]*10001
    inv[10000] = pow(fact[10000],mod-2,mod)
    for i in range(10000)[::-1]:
        inv[i] = inv[i+1]*(i+1)%mod
    k = d+l
    ans = f(x,y)
    if k != x*y:
        ans = f(x,y)-2*f(x-1,y)-2*f(x,y-1)+f(x-2,y)+f(x,y-2)+4*f(x-1,y-1)-2*f(x-2,y-1)-2*f(x-1,y-2)+f(x-2,y-2)
    ans %= mod
    ans *= (w-x+1)*(h-y+1)
    ans *= comb(k,d)
    ans %= mod
    print(ans)
    return

#B
def B():
    n = I()
    d = LIR(n)
    for i in range(n):
        for j in range(n-1):
            d[i][j+1] += d[i][j]
    for j in range(n):
        for i in range(n-1):
            d[i+1][j] += d[i][j]
    for i in range(n):
        d[i].insert(0,0)
    d.insert(0,[0]*(n+1))
    f = [0]*(n**2+1)
    for l in range(n):
        for u in range(n):
            for r in range(l+1,n+1):
                w = r-l
                for d_ in range(u+1,n+1):
                    h = d_-u
                    f[w*h] = max(f[w*h],d[r][d_]-d[r][u]-d[l][d_]+d[l][u])
    q = I()
    for i in range(n**2):
        f[i+1] = max(f[i+1],f[i])
    for i in range(q):
        x = I()
        print(f[x])
    return

#C
def C():
    def cross(a,b):
        return a[0]*b[1]-a[1]*b[0]
    def f(a,b,c,d):
        v = (b[0]-a[0],b[1]-a[1])
        u = (c[0]-a[0],c[1]-a[1])
        u_ = (d[0]-a[0],d[1]-a[1])
        if cross(v,u)*cross(v,u_) <= 0:
            v = (d[0]-c[0],d[1]-c[1])
            u = (a[0]-c[0],a[1]-c[1])
            u_ = (b[0]-c[0],b[1]-c[1])
            if cross(v,u)*cross(v,u_) <= 0:
                return 1
            return 0
        return 0

    p = LI()
    a,b = [p[0],p[1]],[p[2],p[3]]
    n = I()
    p = LIR(n)
    ans = 0
    p.append(p[0])
    for i in range(n):
        c,d = p[i],p[i+1]
        ans += f(a,b,c,d)
    print((ans>>1)+1)
    return

#D
def D():

    return

#E
def E():

    return

#Solve
if __name__ == "__main__":
    A()

Submission

Task問題 D - AtCoder社の冬
User nameユーザ名 tsumugi
Created time投稿日時
Language言語 PyPy3 (2.4.0)
Status状態 AC
Score得点 101
Source lengthソースコード長 2936 Byte
File nameファイル名
Exec time実行時間 192 ms
Memory usageメモリ使用量 40816 KB

Test case

Set

Set name Score得点 / Max score Cases
sub 100 / 100 00_sample_01E.txt,00_sample_02E.txt,00_sample_03E.txt,test_03E.txt,test_04E.txt,test_07E.txt,test_08E.txt,test_11E.txt,test_12E.txt,test_15E.txt,test_16E.txt,test_19E.txt,test_20E.txt,test_23E.txt,test_24E.txt,test_27E.txt,test_28E.txt,test_31E.txt,test_32E.txt,test_36E.txt,test_37E.txt,test_38E.txt,test_39E.txt,test_45E.txt,test_47E.txt
All 1 / 1 00_sample_01E.txt,00_sample_02E.txt,00_sample_03E.txt,00_sample_04.txt,test_01.txt,test_02.txt,test_03E.txt,test_04E.txt,test_05.txt,test_06.txt,test_07E.txt,test_08E.txt,test_09.txt,test_10.txt,test_11E.txt,test_12E.txt,test_13.txt,test_14.txt,test_15E.txt,test_16E.txt,test_17.txt,test_18.txt,test_19E.txt,test_20E.txt,test_21.txt,test_22.txt,test_23E.txt,test_24E.txt,test_25.txt,test_26.txt,test_27E.txt,test_28E.txt,test_29.txt,test_30.txt,test_31E.txt,test_32E.txt,test_33.txt,test_34.txt,test_35.txt,test_36E.txt,test_37E.txt,test_38E.txt,test_39E.txt,test_40.txt,test_41.txt,test_42.txt,test_43.txt,test_44.txt,test_45E.txt,test_46.txt,test_47E.txt,test_48.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
00_sample_01E.txt AC 180 ms 40688 KB
00_sample_02E.txt AC 179 ms 40688 KB
00_sample_03E.txt AC 180 ms 40688 KB
00_sample_04.txt AC 180 ms 40688 KB
test_01.txt AC 181 ms 40688 KB
test_02.txt AC 181 ms 40688 KB
test_03E.txt AC 180 ms 40688 KB
test_04E.txt AC 179 ms 40688 KB
test_05.txt AC 181 ms 40688 KB
test_06.txt AC 180 ms 40688 KB
test_07E.txt AC 180 ms 40688 KB
test_08E.txt AC 181 ms 40688 KB
test_09.txt AC 179 ms 40688 KB
test_10.txt AC 181 ms 40688 KB
test_11E.txt AC 180 ms 40688 KB
test_12E.txt AC 180 ms 40688 KB
test_13.txt AC 181 ms 40688 KB
test_14.txt AC 183 ms 40688 KB
test_15E.txt AC 189 ms 40688 KB
test_16E.txt AC 181 ms 40688 KB
test_17.txt AC 180 ms 40688 KB
test_18.txt AC 183 ms 40688 KB
test_19E.txt AC 179 ms 40688 KB
test_20E.txt AC 180 ms 40688 KB
test_21.txt AC 180 ms 40688 KB
test_22.txt AC 180 ms 40688 KB
test_23E.txt AC 181 ms 40688 KB
test_24E.txt AC 184 ms 40688 KB
test_25.txt AC 190 ms 40688 KB
test_26.txt AC 186 ms 40688 KB
test_27E.txt AC 182 ms 40816 KB
test_28E.txt AC 181 ms 40688 KB
test_29.txt AC 184 ms 40688 KB
test_30.txt AC 189 ms 40688 KB
test_31E.txt AC 185 ms 40688 KB
test_32E.txt AC 192 ms 40688 KB
test_33.txt AC 183 ms 40688 KB
test_34.txt AC 183 ms 40688 KB
test_35.txt AC 183 ms 40688 KB
test_36E.txt AC 183 ms 40688 KB
test_37E.txt AC 185 ms 40688 KB
test_38E.txt AC 183 ms 40688 KB
test_39E.txt AC 183 ms 40688 KB
test_40.txt AC 181 ms 40688 KB
test_41.txt AC 181 ms 40688 KB
test_42.txt AC 181 ms 40688 KB
test_43.txt AC 182 ms 40688 KB
test_44.txt AC 181 ms 40688 KB
test_45E.txt AC 184 ms 40688 KB
test_46.txt AC 180 ms 40688 KB
test_47E.txt AC 181 ms 40688 KB
test_48.txt AC 180 ms 40688 KB