Problem:


Combination of Number Sequences

0 から 9 までの整数を使った n 個の数の並び k1, k2, ..., kn を考えます。正の整数 n と s を読み込んで、

k1 + 2 &times; k2 + 3 &times; k3 + ... + n &times; kn = s 

となっているような n 個の数の並びが何通りあるかを出力するプログラムを作成してください。ただし、1 つの「n 個の数の並び」には同じ数が 2 回以上現われないものとします。

Input

入力は複数のデータセットからなります。各データセットとして、n (1 ≤ n ≤ 10) と s (0 ≤ s ≤ 10,000)が空白区切りで１行に与えられます。

データセットの数は 100 を超えません。

Output

データセットごとに、n 個の整数の和が s になる組み合わせの個数を１行に出力します。

Sample Input

3 10
3 1

Output for the Sample Input

8
0



Sample input:
3 10
3 1


Sample output:
8
0

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, Counter
import sys

# dp[n][使った数字(bit)][合計] = count
dp = [defaultdict(Counter) for _ in [0]*11]
dp[0][0][0] = 0

for i in range(1, 11):
    for used, counter in dp[i-1].items():
        for j in filter(lambda x: used & 2**x == 0, range(10)):
            for total, count in counter.items():
                dp[i][used|2**j][total+j*i] += 1

for n, s in (map(int, l.rstrip().split()) for l in sys.stdin):
    print(sum(v for counter in dp[n].values() for k, v in counter.items() if k == s))

Submission status: Wrong Answer

Solution code:
import time
n = raw_input().split()
s = int(n[1])
n = int(n[0])
ans = 0
def dfs(pos, tmp, tabo):
    #print "pos = %d, tmp = %d" % (pos, tmp)
    #print tabo
    #time.sleep(1)
    if (pos > n + 1 or tmp > s):
        return 
        if (pos == n + 1 and tmp == s):
            global ans
            ans += 1
            return 
            for i in range(10):
                if i not in tabo:
                    n_tmp = tmp + pos * i
                    n_tabo = list(tabo)
                    n_tabo.append(i)
                    dfs(pos + 1, n_tmp, n_tabo)

tabo = []
dfs(1, 0, tabo)
print ans

Submission status: Wrong Answer

Solution code:
n = raw_input().split()
s = int(n[1])
n = int(n[0])
ans = 0
def dfs(pos, tmp, tabo):
    if (pos > n + 1 or tmp > s):
        return 
    if (pos == n + 1 and tmp == s):
        global ans
        ans += 1
        return 
    for i in range(10):
        if i not in tabo:
            n_tmp = tmp + pos * i
            n_tabo = list(tabo)
            n_tabo.append(i)
            dfs(pos + 1, n_tmp, n_tabo)

tabo = []
dfs(1, 0, tabo)
print ans

Submission status: Wrong Answer

Solution code:
import itertools

while True:
	try:
		n,s = map(int,raw_input().split())
	except EOFError:
		break
	
	num = list(itertools.combinations(xrange(10), n))
	
	count = 0
	for var in num:
		if sum(var) == s:
			count += 1
			
	print count

Submission status: Wrong Answer

Solution code:
import itertools

while True:
	try:
		n,s = map(int,raw_input().split())
	except EOFError:
		break
	
	count = 0
	for var in itertools.combinations(range(0, 10), n):
		if sum(var) == s : count += 1
		
	print count

Submission status: Wrong Answer

Solution code:
import sys


def memoize(f):
    memo = {}

    def main(*args):
        if args in memo:
            return memo[args]
        result = memo[args] = f(*args)
        return result

    return main


@memoize
def get_num(remains):
    result = set()
    i = 0
    while remains:
        if remains & 1:
            result.add(i)
        i += 1
        remains >>= 1
    return result


@memoize
def calc(n, s, remains):
    if not n:
        if s:
            return 0
        else:
            return 1
    if s <= 0:
        return 0

    rs = get_num(remains)

    return sum(calc(n - 1, s - n * m, remains ^ (1 << m)) for m in rs)


for line in sys.stdin:
    n, s = map(int, line.split())
    print(calc(n, s, (1 << 10) - 1))

Submission status: Wrong Answer

Solution code:
import sys
def oncount(x):
    r=0
    while x>0:
        r+=x&1
        x=x>>1
    return r

dp=[[0]*331 for i in range(1024)]
for i in range(1024):
    for j in range(331):
        t=oncount(i)
        for k in range(10):
            if 1&(i>>k):
                x=j-t*k
                if x>=0: dp[i][j]+=dp[i&~(1<<k)][x]
for a in sys.stdin:
    n,s=map(int,a.split())
    ans=0
    if 1<=n<=10 and 0<=s<=330:
        for i in range(1024):
            if oncount(i)==n:ans+=dp[i][s]
    print ans

Submission status: Wrong Answer

Solution code:
import sys
def oncount(x):
    r=0
    while x>0:
        r+=x&1
        x=x>>1
    return r

dp=[[0]*331 for i in range(1024)]
for i in range(1024):
    for j in range(331):
        t=oncount(i)
        for k in range(10):
            if 1&(i>>k):
                x=j-t*k
                if x>=0: dp[i][j]+=dp[i&~(1<<k)][x]
                
for a in sys.stdin:
    n,s=map(int,a.split())
    ans=0
    if s<=330:
        for i in range(1024):
            if oncount(i)==n:ans+=dp[i][s]
    print ans

Submission status: Wrong Answer

Solution code:
import sys
def oncount(x):
    r=0
    while x>0:
        r+=x&1
        x=x>>1
    return r

dp=[[0]*331 for i in range(1024)]
for i in range(10):
    dp[1<<i][i]=1
for i in range(1024):
    for j in range(331):
        t=oncount(i)
        for k in range(10):
            if 1&(i>>k):
                x=j-t*k
                if x>=0: dp[i][j]+=dp[i&~(1<<k)][x]
                
for a in range(1):
    n,s=map(int,raw_input().split())
    ans=0
    if s<=330:
        for i in range(1024):
            if oncount(i)==n:ans+=dp[i][s]
    print ans

Submission status: Wrong Answer

Solution code:
def solve(used,rest,sum,memo):
    
    if rest==0:
        return sum==0
    else:
        num=0
        for i in range(10):
            num*=2
            if used[i]:num+=1

        if (num,rest,sum) in memo:
            return memo[(num,rest,sum)]
        if sum<0:return 0
        if sum>maxs[rest]:return 0
        ans=0
        for i in range(10):
            if not used[i]:
                used[i]=True
                ans+=solve(used,rest-1,sum-(i)*rest,memo)
                used[i]=False
        memo[(num,rest,sum)]=ans
        return memo[(num,rest,sum)]

memo={}
while True:
    try:
        n,s=map(int,input().split())
        used=[False for i in range(10)]
        ans=solve(used,n,s,memo)
        print(ans)
    except:
        break

Submission status: Wrong Answer

Solution code:
import itertools

n, s = map(int, raw_input().split())
x = []
for i in range(10):
    x.append(i)

a = list(itertools.permutations(x, n))

u = 0
m = 0


for i in range(len(a)):
    for j in range(n):
        u += a[i][j] * (j + 1)

    if s == u:
        m += 1

    u = 0
print m

Submission status: Wrong Answer

Solution code:
def check(s_i, n_i, count, i_set, memo):
    if (s_i, n_i) in memo:
        return memo[(s, n)]
    for i in range(9):
        i_set_tmp = set(i_set)
        if i not in i_set:
            continue
        if s_i == 0 and n_i == 0:
            return count + 1
        elif s_i < 0 or n_i < 0:
            break
        else:
            s_tmp = s_i - i*n_i
            n_tmp = n_i - 1
            i_set_tmp.remove(i)
            count = check(s_tmp, n_tmp, count, i_set_tmp, memo)
    return count

memo = {}
i_list = [i for i in range(10)]
while True:
    try:
        n, s = map(int, input().split())
        ans = check(s, n, 0, set(i_list), memo)
        memo[(s, n)] = ans
        print(ans)
    except:
        break

Submission status: Wrong Answer

Solution code:
s_max = [0]
for i in range(1,11):
    s = 0
    for j in range(i):
        s += (10 - j - 1)*(i - j)
    s_max.append(s)

s_min = [0,1,4,10,20,35,56,84,120]

def check(s_i, n_i, count, i_set):
    for i in range(9):
        i_set_tmp = set(i_set)
        if i not in i_set:
            continue
        if s_i > s_max[n_i] or s_i < s_min[n_i]:
            continue
        if s_i == 0 and n_i == 0:
            return count + 1
        elif s_i < 0 or n_i < 0:
            break
        else:
            s_tmp = s_i - i*n_i
            n_tmp = n_i - 1
            i_set_tmp.remove(i)
            count = check(s_tmp, n_tmp, count, i_set_tmp)
    return count

i_list = [i for i in range(10)]
while True:
    try:
        n, s = map(int, input().split())
        ans = check(s, n, 0, set(i_list))
        print(ans)
    except:
        break

Submission status: Wrong Answer

Solution code:
import sys,itertools
for l in sys.stdin.readlines():
    n,s=map(int,l.rstrip().split())
    ans=0
    for d in itertools.combinations(range(10),n):
        if sum(d)==s: ans+=1
    print ans

Submission status: Wrong Answer

Solution code:

import sys
import itertools


table = [{}] * 11

def solv(n, s):
    if s > 330:
        return 0
    r = 0
    if table[n]:
        for ps in table[n].keys():
            if table[n][ps] == s:
                r += 0
    else:
        for p in itertools.permutations(xrange(10), n):
            s0 = foo(p, n)
            table[n][str(p)] = s0
            if s0 == s:
                r += 1
    return r


def foo(perm, n):
    return sum(map(lambda x, y: x * y, xrange(1, n+1), perm))


for line in sys.stdin:
    n, s = map(int, line.split(' '))
    print solv(n, s)

Submission status: Wrong Answer

Solution code:

import sys
import itertools


table = [{}] * 11

def solv(n, s):
    if s > 330:
        return 0
    r = 0
    if table[n]:
        for ps in table[n].keys():
            if table[n][ps] == s:
                r += 0
    else:
        for p in itertools.permutations(xrange(10), n):
            s0 = foo(p, n)
            table[n][p] = s0
            if s0 == s:
                r += 1
    return r


def foo(perm, n):
    return sum(map(lambda x, y: x * y, xrange(1, n+1), perm))


for line in sys.stdin:
    n, s = map(int, line.split(' '))
    print solv(n, s)

Submission status: Wrong Answer

Solution code:

import sys
import itertools


table = [{}] * 11

def solv(n, s):
    r = 0
    if table[n]:
        for ps in table[n].keys():
            if table[n][ps] == s:
                r += 0
    else:
        for p in itertools.permutations(xrange(10), n):
            s0 = foo(p, n)
            table[n][p] = s0
            if s0 == s:
                r += 1
    return r


def foo(perm, n):
    return sum(map(lambda x, y: x * y, xrange(1, n+1), perm))


for line in sys.stdin:
    n, s = map(int, line.split(' '))
    print solv(n, s)

Submission status: Wrong Answer

Solution code:

import sys
import itertools


table = [{}] * 11

def solv(n, s):
    r = 0
    if table[n]:
        for ps in table[n].keys():
            if table[n][ps] == s:
                r += 1
    else:
        for p in itertools.permutations(xrange(10), n):
            s0 = foo(p, n)
            table[n][p] = s0
            if s0 == s:
                r += 1
    return r


def foo(perm, n):
    return sum(map(lambda x, y: x * y, xrange(1, n+1), perm))


for line in sys.stdin:
    n, s = map(int, line.split(' '))
    print solv(n, s)

Submission status: Wrong Answer

Solution code:

import sys
import itertools


table = [{}] * 11

def solv(n, s):
    if s > 330:
        return 0
    r = 0
    if table[n]:
        for ps in table[n].keys():
            if table[n][ps] == s:
                r += 1
    else:
        for p in itertools.permutations(xrange(10), n):
            s0 = foo(p, n)
            table[n][p] = s0
            if s0 == s:
                r += 1
    return r


def foo(perm, n):
    return sum(map(lambda x, y: x * y, xrange(1, n+1), perm))


for line in sys.stdin:
    n, s = map(int, line.split(' '))
    print solv(n, s)

Submission status: Wrong Answer

Solution code:
import sys
import itertools


table = [{}] * 11

def solv(n, s):
    if s > 330:
        return 0
    r = 0
    dic = table[n]
    if dic:
        for ps in dic.keys():
            if dic[ps] == s:
                r += 1
    else:
        for p in itertools.permutations(xrange(10), n):
            s0 = foo(p, n)
            dic[p] = s0
            if s0 == s:
                r += 1
    return r


def foo(perm, n):
    return sum(map(lambda x, y: x * y, xrange(1, n+1), perm))


for line in sys.stdin:
    n, s = map(int, line.split(' '))
    print solv(n, s)

Submission status: Wrong Answer

Solution code:
import itertools,sys
for a in sys.stdin:
  c=0
  n,s=map(int,a.split())
  for e in itertools.permutations(range(9),n):
    x=0
    i=n
    for b in e:
      x+=i*b
      i-=1
      if x>s:break
    else:
      if x==s: c+=1
  print c

Submission status: Wrong Answer

Solution code:
def mx(ls,m):
	sum = 0
	for i in range(m):
		sum += (m-i)*ls[-i-1]
	return sum
	
def f(ls,m,s):
	global n
	if mx(ls,m) < s: return 0
	count = 0
	if m > 0:
		for i in range(len(ls)):
			lls = ls[:]
			a = (n-m+1)*lls.pop(i)
			if s-a < 0:	break
			else: count += f(lls,m-1,s-a)
		return count
	else:
		return 1 if s == 0 else 0
			
ls = [i for i in range(10)]
while True:
	try:
		n,s = map(int, raw_input().split())
		print f(ls,n,s)
	except:
		break

Submission status: Wrong Answer

Solution code:
def mx(ls,m):
	sum = 0
	for i in range(m):
		sum += (m-i)*ls[-i-1]
	return sum
	
def f(ls,m,s):
	global n
	count = 0
	if m > 0:
		if mx(ls,m) < s: return 0
		for i in range(len(ls)):
			lls = ls[:]
			a = (n-m+1)*lls.pop(i)
			if s-a < 0:	break
			else: count += f(lls,m-1,s-a)
		return count
	else:
		return 1 if s == 0 else 0
			
ls = [i for i in range(10)]
while True:
	try:
		n,s = map(int, raw_input().split())
		print f(ls,n,s)
	except:
		break

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from itertools import permutations
import sys
for n, s in (map(int, l.rstrip().split()) for l in sys.stdin):
    print(len([1 for a in permutations(range(10), n) if sum(i*n for i,n in enumerate(a, start=1))==s]))

Submission status: Time Limit Exceeded

Solution code:
def dfs(pos, tmp, tabo):
    if (pos > n + 1 or tmp > s):
        return 
    if (pos == n + 1 and tmp == s):
        global ans
        ans += 1
        return 
    for i in range(10):
        if i not in tabo:
            n_tmp = tmp + pos * i
            n_tabo = list(tabo)
            n_tabo.append(i)
            dfs(pos + 1, n_tmp, n_tabo)
while True:
    try:
        n = raw_input().split()
        s = int(n[1])
        n = int(n[0])
        tabo = []
        global ans
        ans = 0
        dfs(1, 0, tabo)
        print ans
    except:
        break

Submission status: Time Limit Exceeded

Solution code:
ans = [[0 for i in range(1024)] for j in range(12)]
def dfs(bit, d, s):
    ans[d][s] += 1
    for i in range(0, 10):
        if (bit & (1 << i)):
            dfs(bit - (1 << i), d + 1, s + (i * (d + 1)))


dfs((1 << 10) - 1, 0, 0)
while True:
    try:
        n,s = map(int, raw_input().split())
        if (s > 1023):
            print 0
        else:
            print ans[n][s]
    except:
        break

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools

def func(li,nu,su):
    count = 0
    if su == 0 and 0 not in li :
        return 1
    elif su < 0 or nu <= 0 or  len(li) == 0:
        return 0
    for e in li:
        lisdot = [ f for f in li if not f == e ]
        count += func(lisdot,nu-1,su-e*nu)
    return count

lis = range(10)
for y in sys.stdin:
    n,s = map(int,y.split())
    print func(lis,n,s)

Submission status: Time Limit Exceeded

Solution code:
import sys

cnt = 0
def solve(n,s,lis):
    global cnt
    if n<0 or s<0:
        return 0
    elif n == 0 and s == 0:
        cnt += 1
        return 0
    else :
        for i in xrange(len(lis)):
            solve(n-1,s-n*lis[i],[ lis[j] for j in xrange(len(lis)) if not i == j ])
        return cnt

for s in sys.stdin:
    cnt = 0
    n,s = map(int,s.split())
    lis = range(10)
    print solve(n,s,lis)

Submission status: Time Limit Exceeded

Solution code:
import sys

cnt = 0
def solve(n,s,lis):
    global cnt
    if n<0 or s<0:
        return 0
    elif n == 0 and s == 0:
        cnt += 1
        return 0
    else :
        for i in xrange(len(lis)):
            ll = lis[:]
            a = s-n*ll.pop(i)
            solve(n-1,a,ll )
        return cnt

for s in sys.stdin:
    cnt = 0
    n,s = map(int,s.split())
    lis = range(10)
    print solve(n,s,lis)

Submission status: Time Limit Exceeded

Solution code:
import sys

cnt = 0
def solve(n,s,lis):
    global cnt
    if n<0 or s<0:
        return 0
    elif n == 0 and s == 0:
        cnt += 1
        return 0
    else :
        for i in xrange(len(lis)):
            ll = lis[:]
            a = s-n*ll.pop(i)
            if n-1 < 0 or a<0:
                break
            solve(n-1,a,ll )
        return cnt

for s in sys.stdin:
    cnt = 0
    n,s = map(int,s.split())
    lis = range(10)
    print solve(n,s,lis)

Submission status: Time Limit Exceeded

Solution code:
import sys

cnt = 0
def solve(n,s,lis):
    global cnt
    if n == 0 and s == 0:
        cnt += 1
        return 0
    else :
        for i in xrange(len(lis)):
            ll = lis[:]
            a = s-n*ll.pop(i)
            if n-1<0 or a<0:
                break
            solve(n-1,a,ll )
        return cnt

for s in sys.stdin:
    cnt = 0
    n,s = map(int,s.split())
    lis = range(10)
    print solve(n,s,lis)

Submission status: Time Limit Exceeded

Solution code:
import itertools

import sys
f = sys.stdin

for line in f:
    n, s = map(int, line.split())
    print(sum(1 for k in itertools.permutations(range(10), n) if s == sum(k[i] * (i + 1) for i in range(n))))

Submission status: Time Limit Exceeded

Solution code:
import sys
f = sys.stdin

def solve(k,n,s):
    if n == 1:
        return 1 if s in k else 0
    ret = 0
    for ki in k:
        value = n * ki
        if s >= value:
            sub = k[:]
            sub.remove(ki)
            ret += solve(sub,n - 1,s - value)
    return ret
        
for line in f:
    n, s = map(int, line.split())
    print(solve(list(range(10)),n,s))

Submission status: Time Limit Exceeded

Solution code:
import sys
f = sys.stdin



def solve(k,n,s):
    if n == 1:
        return 1 if s in k else 0
    ret = 0
    for ki in k:
        value = n * ki
        if s >= value:
            sub = k[:]
            sub.remove(ki)
            mini = sum(i * j for i, j in zip(range(n - 1,0,-1), sub))
            maxi = sum(i * j for i, j in zip(range(n - 1,0,-1), sub[::-1]))
            if mini <= s - value <= maxi:
                ret += solve(sub,n - 1,s - value)
    return ret
        
for line in f:
    n, s = map(int, line.split())
    print(solve(list(range(10)),n,s))

Submission status: Time Limit Exceeded

Solution code:
import sys

def shy(c_p, m_c, flag):
    for i in range(m_c):
        k.append(c_p + i)
        if flag == n:
            hope(k)
        else:
            shy(c_p+i+1, m_c, flag+1)
            m_c -= 1
        del k[-1]
            
def hope(k):
    global count
    if k:
        for i, v in enumerate(k):
            three.append(v)
            hope(k[:i]+k[i+1:])
            del three[-1]
    else:
        ans = 0
        for i in range(n):
            multiple = i+1
            ans += (multiple * three[i])
        else:
            if ans == s:
                count += 1

for line in sys.stdin:
    n, s = map(int, line.rstrip().split())
    k = []
    three = []
    count = 0
    m_c = 10 - n + 1
    shy(0, m_c, 1)
    print count

Submission status: Time Limit Exceeded

Solution code:
def get_s():
    while True:
        try:
            yield raw_input()
        except EOFError:
            break

def shy(c_p, m_c, flag):
    for i in range(m_c):
        k.append(c_p + i)
        if flag == n:
            hope(k)
        else:
            shy(c_p+i+1, m_c, flag+1)
            m_c -= 1
        del k[-1]
            
def hope(k):
    global count
    if k:
        for i, v in enumerate(k):
            three.append(v)
            hope(k[:i]+k[i+1:])
            del three[-1]
    else:
        ans = 0
        for i in range(n):
            multiple = i+1
            ans += (multiple * three[i])
        else:
            if ans == s:
                count += 1

for line in list(get_s()):
    n, s = map(int, line.split())
    three = []
    k = []
    count = 0
    m_c = 10 - n + 1
    shy(0, m_c, 1)
    print count

Submission status: Time Limit Exceeded

Solution code:
def get_s():
    while True:
        try:
            yield raw_input()
        except EOFError:
            break

def shy(c_p, m_c, flag):
    for i in range(m_c):
        k.append(c_p + i)
        if flag == n:
            hope(k)
        else:
            shy(c_p+i+1, m_c, flag+1)
            m_c -= 1
        del k[-1]
            
def hope(k):
    global count
    if k:
        for i, v in enumerate(k):
            three.append(v)
            hope(k[:i]+k[i+1:])
            del three[-1]
    else:
        ans = 0
        for i in range(n):
            multiple = i+1
            ans += (multiple * three[i])
        else:
            if ans == s:
                count += 1

a = list(get_s())
for line in a:
    n, s = map(int, line.split())
    three = []
    k = []
    count = 0
    m_c = 10 - n + 1
    shy(0, m_c, 1)
    print count

Submission status: Time Limit Exceeded

Solution code:
import sys

def shy(c_p, m_c, flag):
    for i in range(m_c):
        k.append(c_p + i)
        if flag == n:
            hope(k)
        else:
            shy(c_p+i+1, m_c, flag+1)
            m_c -= 1
        del k[-1]
            
def hope(k):
    global count
    if k:
        for i, v in enumerate(k):
            three.append(v)
            hope(k[:i]+k[i+1:])
            del three[-1]
    else:
        ans = 0
        for i in range(n):
            multiple = i+1
            ans += (multiple * three[i])
        else:
            if ans == s:
                count += 1

for line in sys.stdin:
    n, s = map(int, line.split())
    k = []
    three = []
    count = 0
    m_c = 10 - n + 1
    shy(0, m_c, 1)
    print count

Submission status: Time Limit Exceeded

Solution code:
def shy(c_p, m_c, flag):
    for i in range(m_c):
        k.append(c_p + i)
        if flag == n:
            hope(k)
        else:
            shy(c_p+i+1, m_c, flag+1)
            m_c -= 1
        del k[-1]
            
def hope(k):
    global count
    if k:
        for i, v in enumerate(k):
            three.append(v)
            hope(k[:i]+k[i+1:])
            del three[-1]
    else:
        ans = 0
        for i in range(n):
            multiple = i+1
            ans += (multiple * three[i])
        else:
            if ans == s:
                count += 1

while True:
    try:
        n, s = map(int, raw_input().split())
        k = []
        three = []
        count = 0
        m_c = 10 - n + 1
        shy(0, m_c, 1)
        print count
    except EOFError:
        break

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import permutations

for line in sys.stdin:
    n, s = map(int, line.split())
    count = 0
    for combi in permutations(range(10), n):
        if sum(x * y for (x, y) in zip(range(1, 10), combi)) == s:
            count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
def dfs(cnt,wa):
	global ans
	if cnt==n+1:return
	if wa==0 and cnt==n:
		ans+=1
		return 
	for  i in xrange(10):
		if not used[i]:
			used[i]=True
			dfs(cnt+1,wa-(cnt+1)*i)
			used[i]=False
	return 
	
while 1:
	try:
		n,s=map(int,raw_input().split())
		ans=0
		used=[False]*10
		dfs(0,s)
		print(ans)
	except:
		break

Submission status: Time Limit Exceeded

Solution code:
import sys
def line():return sys.stdin.readline().strip()

import itertools
k = (0,1,2,3,4,5,6,7,8,9)

while True:
    try:
        cnt = 0
        n,s = map(int,line().split())
        for tpl in itertools.permutations(k,n):
            t = 0
            for i in range(len(tpl)): t+=tpl[i] * (i + 1)
            if t == s:cnt+=1
        print(cnt)
    except:
        break

Submission status: Time Limit Exceeded

Solution code:
# ??°??????????????????????????§???????????°??????
import sys

def get_sequence(s, n, k, ks):
    # s : ????¨?
    # n : n????????°???
    # k : k???????????°???????????????(1???10)
    # ks: ?????¨?????????????????°???

    if k == n:

        if s % k == 0:
            if s // k in ks:
                #print('s:{} k:{} n:{} ks:'.format(s, k, n), end='')
                print(ks)
                return 1
            else:
                return 0
        else:
            return 0

    cnt = 0
    for i in ks:
        s_copy = s
        s_copy -= i * k
        if s_copy < 0:
            break
        
        k_copy = k
        k_copy += 1
        if k_copy > n:
            break
        
        ks_copy = ks[:]
        ks_copy.remove(i)
        #print('i:', i)
        cnt += get_sequence(s_copy, n, k_copy, ks_copy)

    return cnt
        
def main():
    while True:
        line = sys.stdin.readline().strip()
        if line is None or line == '':
            break

        data = line.split(' ')
        n = int(data[0])
        s = int(data[1])
        cnt = get_sequence(s, n, 1, list(range(10)))
        print(cnt)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# ??°??????????????????????????§???????????°??????
import sys

def get_sequence(s, n, k, ks):
    # s : ????¨?
    # n : n????????°???
    # k : k???????????°???????????????(1???10)
    # ks: ?????¨?????????????????°???

    if k == n:

        if s % k == 0:
            if s // k in ks:
                #print('s:{} k:{} n:{} ks:'.format(s, k, n), end='')
                #print(ks)
                return 1
            else:
                return 0
        else:
            return 0

    cnt = 0
    for i in ks:
        s_copy = s
        s_copy -= i * k
        if s_copy < 0:
            break
        
        k_copy = k
        k_copy += 1
        if k_copy > n:
            break
        
        ks_copy = ks[:]
        ks_copy.remove(i)
        #print('i:', i)
        cnt += get_sequence(s_copy, n, k_copy, ks_copy)

    return cnt
        
def main():
    while True:
        line = sys.stdin.readline().strip()
        if line is None or line == '':
            break

        data = line.split(' ')
        n = int(data[0])
        s = int(data[1])
        cnt = get_sequence(s, n, 1, list(range(10)))
        print(cnt)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# ??°??????????????????????????§???????????°??????
import sys

def get_max():
    numbers = list(range(10))
    sum = 0

    for idx, num in enumerate(numbers, 1):
        sum += (idx * num)

    return sum

def get_sequence(s, n, k, ks):
    # s : ????¨?
    # n : n????????°???
    # k : k???????????°???????????????(1???10)
    # ks: ?????¨?????????????????°???

    if k == n:
        if s % k == 0 and s // k in ks:
            return 1
        else:
            return 0

    cnt = 0
    for i in ks:
        s_copy = s
        s_copy -= i * k
        if s_copy < 0:
            break
        
        k_copy = k
        k_copy += 1
        if k_copy > n:
            break
        
        ks_copy = ks[:]
        ks_copy.remove(i)
        cnt += get_sequence(s_copy, n, k_copy, ks_copy)

    return cnt
        
def main():
    max_s = get_max()
    
    while True:
        line = sys.stdin.readline().strip()
        if line is None or line == '':
            break

        data = line.split(' ')
        n = int(data[0])
        s = int(data[1])
        if s > max_s:
            print(0)
        else:
            cnt = get_sequence(s, n, 1, list(range(10)))
            print(cnt)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# ??°??????????????????????????§???????????°??????
import sys

def get_max(n):
    numbers = list(range(n))
    sum = 0

    for idx, num in enumerate(numbers, 1):
        sum += (idx * num)

    return sum

def get_sequence(s, n, k, ks):
    # s : ????¨?
    # n : n????????°???
    # k : k???????????°???????????????(1???10)
    # ks: ?????¨?????????????????°???

    if k == n:
        if s % k == 0 and s // k in ks:
            return 1
        else:
            return 0

    cnt = 0
    for i in ks:
        s_copy = s
        s_copy -= i * k
        if s_copy < 0:
            break
        
        k_copy = k
        k_copy += 1
        if k_copy > n:
            break
        
        ks_copy = ks[:]
        ks_copy.remove(i)
        cnt += get_sequence(s_copy, n, k_copy, ks_copy)

    return cnt
        
def main():
    
    while True:
        line = sys.stdin.readline().strip()
        if line is None or line == '':
            break

        data = line.split(' ')
        n = int(data[0])
        s = int(data[1])
        max_s = get_max(n)
        
        if s > max_s:
            print(0)
        else:
            cnt = get_sequence(s, n, 1, list(range(10)))
            print(cnt)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# ??°??????????????????????????§???????????°??????
import sys

def get_max():
    max_s = []
    for i in range(1, 11):
        sum = 0
        for j in range(i):
            sum += (9-j) * (i-j)

        max_s.append(sum)

    return max_s

def get_sequence(s, n, k, ks):
    # s : ????¨?
    # n : n????????°???
    # k : k???????????°???????????????(1???10)
    # ks: ?????¨?????????????????°???

    if k == n:
        if s % k == 0 and s // k in ks:
            return 1
        else:
            return 0

    cnt = 0
    for i in ks:
        s_copy = s
        s_copy -= i * k
        if s_copy < 0:
            break
        
        k_copy = k
        k_copy += 1
        if k_copy > n:
            break
        
        ks_copy = ks[:]
        ks_copy.remove(i)
        cnt += get_sequence(s_copy, n, k_copy, ks_copy)

    return cnt
        
def main():
    max_s = get_max()
    print(max_s)
    
    while True:
        line = sys.stdin.readline().strip()
        if line is None or line == '':
            break

        data = line.split(' ')
        n = int(data[0])
        s = int(data[1])
        
        if s > max_s[n-1]:
            print(0)
        else:
            cnt = get_sequence(s, n, 1, list(range(10)))
            print(cnt)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# ??°??????????????????????????§???????????°??????
import sys

def get_max():
    max_s = []
    for i in range(1, 11):
        sum = 0
        for j in range(i):
            sum += (9-j) * (i-j)

        max_s.append(sum)

    return max_s

def get_sequence(s, n, k, ks):
    # s : ????¨?
    # n : n????????°???
    # k : k???????????°???????????????(1???10)
    # ks: ?????¨?????????????????°????????????

    if k == n:
        if s % k == 0 and s // k in ks:
            return 1
        else:
            return 0

    if k > n:
        return 0

    cnt = 0
    for i in ks:
        s_copy = s
        s_copy -= i * k
        if s_copy < 0:
            break
        
        ks_copy = ks[:]
        ks_copy.remove(i)
        cnt += get_sequence(s_copy, n, k+1, ks_copy)

    return cnt
        
def main():
    max_s = get_max()
    print(max_s)
    
    while True:
        line = sys.stdin.readline().strip()
        if line is None or line == '':
            break

        data = line.split(' ')
        n = int(data[0])
        s = int(data[1])
        
        if s > max_s[n-1]:
            print(0)
        else:
            cnt = get_sequence(s, n, 1, list(range(10)))
            #print(cnt)

if __name__ == '__main__':
    main()