AtCoder Beginner Contest 002

Submission #6903154

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():
    w = I()
    n,k = LI()
    g = LIR(n)
    dp = [[0]*(w+1) for i in range(k+1)]
    for d in range(n):
        a,b = g[d]
        for i in range(1,k+1)[::-1]:
            for j in range(a,w+1)[::-1]:
                dp[i][j] = max(dp[i][j],dp[i-1][j-a]+b)
    ans = 0
    for i in range(k+1):
        ans = max(ans,max(dp[i]))
    print(ans)
    return

#E
def E():
    n,m = LI()
    v = [[0]*n for i in range(n)]
    for i in range(n):
        v[i][i] = 1
    for i in range(m):
        x,y = LI()
        x -= 1
        y -= 1
        v[x][y] = 1
        v[y][x] = 1
    m = 1<<n
    ans = 0
    for k in range(m):
        bi = bin(k).count("1")
        for i in range(n):
            if not k&(1<<i):
                continue
            for j in range(n):
                if not k&(1<<j):
                    continue
                if not v[i][j]:
                    break
            else:
                continue
            break
        else:
            ans = max(ans,bi)
    print(ans)
    return

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

Submission

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

Test case

Set

Set name Score得点 / Max score Cases
all 100 / 100 00_sample_01.txt,00_sample_02.txt,00_sample_03.txt,00_sample_04.txt,test_01.txt,test_02.txt,test_03.txt,test_04.txt,test_05.txt,test_06.txt,test_07.txt,test_08.txt,test_09.txt,test_10.txt,test_11.txt,test_12.txt,test_13.txt,test_14.txt,test_15.txt,test_16.txt,test_17.txt,test_18.txt,test_19.txt,test_20.txt,test_21.txt,test_22.txt,test_23.txt,test_24.txt,test_25.txt,test_26.txt,test_27.txt,test_28.txt,test_29.txt,test_30.txt,test_31.txt,test_32.txt,test_33.txt,test_34.txt,test_35.txt,test_36.txt,test_37.txt,test_38.txt,test_39.txt,test_40.txt,test_41.txt,test_42.txt,test_43.txt,test_44.txt,test_45.txt,test_46.txt,test_47.txt,test_48.txt,test_49.txt,test_50.txt,test_51.txt,test_52.txt,test_53.txt,test_54.txt,test_55.txt,test_56.txt,test_57.txt,test_58.txt,test_59.txt,test_60.txt,test_61.txt,test_62.txt,test_63.txt,test_64.txt,test_65.txt,test_66.txt,test_67.txt,test_68.txt,test_69.txt,test_70.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
00_sample_01.txt AC 204 ms 39408 KB
00_sample_02.txt AC 202 ms 39408 KB
00_sample_03.txt AC 205 ms 39408 KB
00_sample_04.txt AC 226 ms 42352 KB
test_01.txt AC 202 ms 39408 KB
test_02.txt AC 197 ms 39408 KB
test_03.txt AC 198 ms 39408 KB
test_04.txt AC 207 ms 39408 KB
test_05.txt AC 203 ms 39408 KB
test_06.txt AC 219 ms 39408 KB
test_07.txt AC 209 ms 39408 KB
test_08.txt AC 213 ms 40944 KB
test_09.txt AC 232 ms 42096 KB
test_10.txt AC 224 ms 41200 KB
test_11.txt AC 226 ms 42096 KB
test_12.txt AC 243 ms 42480 KB
test_13.txt AC 199 ms 39408 KB
test_14.txt AC 208 ms 39408 KB
test_15.txt AC 214 ms 40304 KB
test_16.txt AC 224 ms 42096 KB
test_17.txt AC 229 ms 42096 KB
test_18.txt AC 225 ms 42352 KB
test_19.txt AC 243 ms 43248 KB
test_20.txt AC 240 ms 42608 KB
test_21.txt AC 235 ms 42096 KB
test_22.txt AC 251 ms 42736 KB
test_23.txt AC 245 ms 42736 KB
test_24.txt AC 237 ms 42224 KB
test_25.txt AC 195 ms 39408 KB
test_26.txt AC 235 ms 42864 KB
test_27.txt AC 220 ms 41712 KB
test_28.txt AC 202 ms 39408 KB
test_29.txt AC 216 ms 40944 KB
test_30.txt AC 230 ms 41584 KB
test_31.txt AC 227 ms 42608 KB
test_32.txt AC 234 ms 42224 KB
test_33.txt AC 229 ms 42864 KB
test_34.txt AC 246 ms 42096 KB
test_35.txt AC 255 ms 43628 KB
test_36.txt AC 229 ms 42224 KB
test_37.txt AC 218 ms 41840 KB
test_38.txt AC 227 ms 42608 KB
test_39.txt AC 241 ms 42352 KB
test_40.txt AC 226 ms 41840 KB
test_41.txt AC 253 ms 44140 KB
test_42.txt AC 226 ms 42224 KB
test_43.txt AC 215 ms 41712 KB
test_44.txt AC 230 ms 41968 KB
test_45.txt AC 236 ms 42352 KB
test_46.txt AC 252 ms 42352 KB
test_47.txt AC 238 ms 42736 KB
test_48.txt AC 223 ms 42224 KB
test_49.txt AC 227 ms 42480 KB
test_50.txt AC 231 ms 42352 KB
test_51.txt AC 243 ms 41712 KB
test_52.txt AC 247 ms 42352 KB
test_53.txt AC 229 ms 41968 KB
test_54.txt AC 239 ms 41964 KB
test_55.txt AC 243 ms 43376 KB
test_56.txt AC 253 ms 44656 KB
test_57.txt AC 230 ms 42736 KB
test_58.txt AC 235 ms 42864 KB
test_59.txt AC 238 ms 42864 KB
test_60.txt AC 230 ms 42224 KB
test_61.txt AC 240 ms 43928 KB
test_62.txt AC 193 ms 39408 KB
test_63.txt AC 225 ms 41968 KB
test_64.txt AC 222 ms 42480 KB
test_65.txt AC 227 ms 41968 KB
test_66.txt AC 232 ms 42224 KB
test_67.txt AC 236 ms 42480 KB
test_68.txt AC 234 ms 42224 KB
test_69.txt AC 244 ms 41968 KB
test_70.txt AC 247 ms 42736 KB