problem_id
stringlengths 6
6
| user_id
stringlengths 10
10
| time_limit
float64 1k
8k
| memory_limit
float64 262k
1.05M
| problem_description
stringlengths 48
1.55k
| codes
stringlengths 35
98.9k
| status
stringlengths 28
1.7k
| submission_ids
stringlengths 28
1.41k
| memories
stringlengths 13
808
| cpu_times
stringlengths 11
610
| code_sizes
stringlengths 7
505
|
---|---|---|---|---|---|---|---|---|---|---|
p03805 | u765590009 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['def dfs(place,number,checkedList,path):\n checkedList[place] = 1\n if sum(checked) == number:\n return 1\n pathNumber = 0\n for i in path[place]:\n if checkedList[i] == 1:\n continue\n pathNumber += dfs(i,number,checkedList,path)\n checkedList[i] = 0\n return pathNumber \n\nn, m = map(int, input().split())\n\nchecked = [0] * 8\npath = [ [] for _ in range(8)]\nfor i in range(m):\n a, b = map(int, input().split())\n path[a-1].append(b-1)\n path[b-1].append(a-1)\n print(path)\n \nprint(dfs(0,n,checked,path))', 'def dfs(place,number,checkedList,path):\n checkedList[place] = 1\n if sum(checked) == number:\n return 1\n pathNumber = 0\n for i in path[place]:\n if checkedList[i] == 1:\n continue\n pathNumber += dfs(i,number,checkedList,path)\n checkedList[i] = 0\n return pathNumber \n\nn, m = map(int, input().split())\n\nchecked = [0] * 8\npath = [ [] for _ in range(8)]\nfor i in range(m):\n a, b = map(int, input().split())\n path[a-1].append(b-1)\n path[b-1].append(a-1)\n #print(path)\n \nprint(dfs(0,n,checked,path))'] | ['Wrong Answer', 'Accepted'] | ['s342424573', 's628744245'] | [9124.0, 9076.0] | [33.0, 33.0] | [516, 517] |
p03805 | u769852547 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['n, m = map(int, input().split())\nab = [ list(map(int, input().split())) for _ in range(m) ]\n\ngraph = [ [False] * 8 for _ in range(8) ]\nvisited = [False] * n\n\ndef dfs(a, N, visited):\n finish = True\n for i in range(N):\n if not visited[i]:\n finish = False\n if finish:\n return 1\n ans = 0\n for i in range(N):\n if not graph[a][i] or visited[i]:\n continue\n visited[i] = True\n ans += dfs(i,N,visited)\n visited[i] = False\n\nfor i in range(m):\n graph[ab[i][0]-1][ab[i][1]-1], graph[ab[i][1]-1][ab[i][0]-1] = True, True\n\nvisited[0] = True\nprint(dfs(0,n,visited))', 'n, m = map(int, input().split())\nab = [ list(map(int, input().split())) for _ in range(m) ]\n\ngraph = [ [False] * 8 for _ in range(8) ]\nvisited = [False] * n\n\ndef dfs(a, N, visited):\n finish = True\n for i in range(N):\n if not visited[i]:\n finish = False\n if finish:\n return 1\n ans = 0\n for i in range(N):\n if not graph[a][i] or visited[i]:\n continue\n visited[i] = True\n ans += dfs(i,N,visited)\n visited[i] = False\n return ans\n\nfor i in range(m):\n graph[ab[i][0]-1][ab[i][1]-1], graph[ab[i][1]-1][ab[i][0]-1] = True, True\n\nvisited[0] = True\nprint(dfs(0,n,visited))'] | ['Runtime Error', 'Accepted'] | ['s288863898', 's452739037'] | [3064.0, 3064.0] | [18.0, 34.0] | [632, 647] |
p03805 | u780962115 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['n,m=map(int,input().split())\nuselist=[]\nfor _ in range(m):\n ad=list(map(int,input().split()))\n uselist.append(ad)\ncnt=0\nfor i in itertools.permutations(range(1,n+1)):\n if i[0]==1:\n flag=True\n for j in range(n-1):\n if [i[j],i[j+1]] not in uselist and [i[j+1], i[j]] not in uselist:\n flag =False\n break\n else:\n continue\n if flag==True:\n cnt+=1\n else:\n continue\n \nprint(cnt) ', 'N,M=map(int,input().split())\nimport itertools\ngraph={i:{} for i in range(1,N+1)}\nfor _ in range(M):\n a,b=map(int,input().split())\n graph[a][b]=1\n graph[b][a]=1\n \nseq=[i+1 for i in range(N)]\nQ=list(itertools.permutations(seq))\nans=0\nfor que in Q:\n flag=True\n s=que[0]\n if s!=1:\n flag=False\n for i in range(1,N):\n node=que[i]\n if node in graph[s]:\n s=node\n else:\n flag=False\n if flag==False:\n break\n ans+=int(flag)\nprint(ans) '] | ['Runtime Error', 'Accepted'] | ['s601057728', 's699231124'] | [3064.0, 8052.0] | [18.0, 76.0] | [517, 522] |
p03805 | u785578220 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['from itertools import permutations\n\nn,m=map(int,input().split())\npath=set()\nfor _ in range(m):\n u,v=map(int,input().split())\n path|={(u-1,v-1),(v-1,u-1)}\ns = 0\nfor i in permutations(range(n)):\n s+=(all((h,j) in path for h,j in zip(i[1:],i))) if i[0] ==0\nprint(s)', '\n#########\n#thiking Face\nfrom itertools import permutations\n\nn,m=map(int,input().split())\npath=set()\nfor _ in range(m):\n u,v=map(int,input().split())\n path|={(u-1,v-1),(v-1,u-1)}\n\nprint(sum(all((u,v) in es for u,v in zip(p,p[1:]))\n for p in permutations(range(n)) if p[0]==0))\n', '###########\n\n#########\n#thiking Face\nfrom itertools import permutations\n\nn,m=map(int,input().split())\npath=set()\nfor _ in range(m):\n u,v=map(int,input().split())\n path|={(u-1,v-1),(v-1,u-1)}\n\nprint(sum(all((u,v) in es for u,v in zip([0]+p,p))\n for p in permutations(range(1,n))))\n\n', 'from itertools import permutations\n\nn,m=map(int,input().split())\npath=set()\nfor _ in range(m):\n u,v=map(int,input().split())\n path|={(u-1,v-1),(v-1,u-1)}\ns = 0\nfor i in permutations(range(n)):\n if i[0] ==0:\n\n s+=(all((h,j) in path for h,j in zip(i[1:],i)))\n\n\nprint(s)'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s328568564', 's339701210', 's403240898', 's399706532'] | [2940.0, 3060.0, 3060.0, 3064.0] | [17.0, 18.0, 18.0, 31.0] | [271, 292, 296, 283] |
p03805 | u787059958 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['from collections import defaultdict, deque\nN, M = map(int, input().split())\n\nd = defaultdict(list)\nfor _ in range(M):\n a, b = map(int, input().split())\n d[a].append(b)\n d[b].append(a)\n\nprint(d)\n\n\ndef dfs(n, check):\n check[n - 1] = True\n for i in range(len(d[n])):\n if not check[d[n][i] - 1]:\n check[d[n][i] - 1] = True\n return dfs(d[n][i], check)\n\n return check\n\n\ncount = 0\nfor i in range(len(d[1])):\n check = [False] * N\n check[0] = True\n c = dfs(d[1][i], check)\n if False not in c:\n count += 1\n\nprint(count)\n', 'import itertools\nn, m = map(int, input().split())\nab = {}\nfor i in range(n+1):\n ab[i] = []\nfor i in range(m):\n a, b = map(int, input().split())\n ab[a].append(b)\n ab[b].append(a)\nprint(ab) \ncount = 0\n \nfor values in list(itertools.permutations(range(2, n+1))):\n pre = 1\n for i, v in enumerate(values):\n if(v not in ab[pre]):\n break\n if i == n-2:\n count += 1\n pre = v\n\nprint(count)', 'from collections import defaultdict\nN, M = map(int, input().split())\nd = defaultdict(list)\nfor _ in range(M):\n a, b = map(int, input().split())\n d[a].append(b)\n d[b].append(a)\n\n\ndef dfs(n, path):\n count = 0\n path.append(n)\n if len(path) == N:\n count += 1\n return count\n\n for i in range(len(d[n])):\n if d[n][i] not in path:\n count += dfs(d[n][i], path)\n path.pop()\n\n return count\n\n\nprint(dfs(1, []))\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s049497912', 's746411143', 's677782453'] | [9408.0, 3572.0, 9436.0] | [28.0, 30.0, 43.0] | [576, 440, 466] |
p03805 | u787449825 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['from itertools import permutations\n\nn, m = map(int, input().split())\nans = 0\n\npath = [[False]*n for i in range(n)]\nfor i in range(m):\n a, b = map(int, input().split())\n a -= 1\n b -= 1\n path[a][b] = True\n path[b][a] = True\n\nfor i in permutations(range(n), n):\n if i[0] == 0:\n for j in range(n):\n if not path[i[j]][i[j+1]]:\n break\n if j == n-1:\n ans += 1\n break\nprint(ans)\n', ' from itertools import permutations\n\nn, m = map(int, input().split())\nans = 0\n\npath = [[False]*n for i in range(n)]\nfor i in range(m):\n a, b = map(int, input().split())\n a -= 1\n b -= 1\n path[a][b] = True\n path[b][a] = True\n\nfor i in permutations(range(n), n):\n if i[0] == 0:\n for j in range(n):\n if j == 1:\n ans += 1\n break\n if not path[i[j]][i[j+1]]:\n break\nprint(ans)', ' from itertools import permutations\n\nn, m = map(int, input().split())\nans = 0\n\npath = [[False]*n for i in range(n)]\nfor i in range(m):\n a, b = map(int, input().split())\n a -= 1\n b -= 1\n path[a][b] = True\n path[b][a] = True\n\nfor i in permutations(range(n), n):\n if i[0] == 0:\n for j in range(n):\n if j == n - 1:\n ans += 1\n break\n if not path[i[j]][i[j+1]]:\n break\nprint(ans)\n', 'from itertools import permutations\n\nn, m = map(int, input().split())\nans = 0\n\npath = [[False]*n for i in range(n)]\nfor i in range(m):\n a, b = map(int, input().split())\n a -= 1\n b -= 1\n path[a][b] = True\n path[b][a] = True\n\nfor i in permutations(range(n), n):\n if i[0] == 0:\n for j in range(n):\n if j == n - 1:\n ans += 1\n break\n if not path[i[j]][i[j+1]]:\n break\nprint(ans)'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s244942967', 's568000202', 's581598895', 's201599976'] | [3064.0, 2940.0, 2940.0, 3064.0] | [25.0, 18.0, 17.0, 32.0] | [463, 476, 481, 464] |
p03805 | u809457879 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['from collections import deque\nN,M=map(int,input().split())\nl=[[] for _ in range(N)]\nfor _ in range(M):\n x,y=map(int,input().split())\n l[x-1].append(y-1)\n l[y-1].append(x-1)\n\ndef dfs(N,l):\n stack=deque()\n check=[] \n ans=0\n s=0\n t=0\n for i in l[0]:\n stack.append(i)\n check.append(0)\n while stack:\n a=stack.pop()\n if a not in check:\n check.append(a)\n if len(check)==N:\n ans+=1\n print(check)\n check.pop()\n else:\n for j in l[a]:\n stack.append(j)\n else:\n continue\n return ans\nprint(dfs(N,l))', "from itertools import permutations\nN,M=map(int,input().split())\nl=[[] for _ in range(N)]\nfor _ in range(M):\n x,y=map(int,input().split())\n l[x-1].append(y-1)\n l[y-1].append(x-1)\n\nres=0\nfor i in permutations(range(2,N+1)):\n s='1'\n for j in i:\n s+=str(j)\n ans=True\n for k in range(N-1):\n ss=int(s[k])-1\n st=int(s[k+1])-1\n if st not in l[ss]:\n ans=False\n if ans:\n res+=1\nprint(res)"] | ['Wrong Answer', 'Accepted'] | ['s997401439', 's545350027'] | [3316.0, 3064.0] | [21.0, 60.0] | [582, 406] |
p03805 | u813450984 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['n, m = map(int, input().split())\nl = []\ncombo = []\nfor i in range(max(n, m) + 1):\n l.append([])\ndef dfs(path, now):\n if len(set(path)) == n and not path in combo:\n combo.append(path)\n return\n\n for i in l[now]:\n if not i in path:\n temp = path[:]\n temp.append(i)\n dfs(temp, i)\n\n return\n\nif m == 0:\n print(0)\nelse:\n\n for i in range(m):\n f, t = map(int, input().split())\n if not t in l[f]:\n l[f].append(t)\n \n if not f in l[t]:\n l[t].append(f)\n\n dfs([1], 1)\n print(len(combo))n, m = map(int, input().split())\nl = []\ncombo = []\nfor i in range(max(n, m) + 1):\n l.append([])\ndef dfs(path, now):\n if len(set(path)) == n and not path in combo:\n combo.append(path)\n return\n\n for i in l[now]:\n if not i in path:\n temp = path[:]\n temp.append(i)\n dfs(temp, i)\n\n return\n\nif m == 0:\n print(0)\nelse:\n\n for i in range(m):\n f, t = map(int, input().split())\n if not t in l[f]:\n l[f].append(t)\n \n if not f in l[t]:\n l[t].append(f)\n\n dfs([1], 1)\n print(len(combo))', 'n, m = map(int, input().split())\nl = []\ncombo = []\nfor i in range(max(n, m)+1):\n l.append([])\n \ndef dfs(path, now):\n if len(set(path)) == n and not path in combo:\n combo.append(path)\n return\n\n for i in l[now]:\n if not i in path:\n temp = path[:]\n temp.append(i)\n dfs(temp, i)\n\n return\n\nif m == 0:\n print(0)\nelse:\n\n for i in range(m):\n f, t = map(int, input().split())\n if not t in l[f]:\n l[f].append(t)\n \n if not f in l[t]:\n l[t].append(f)\n\n dfs([1], 1)\n print(len(combo))'] | ['Runtime Error', 'Accepted'] | ['s102264496', 's137829404'] | [3064.0, 3832.0] | [17.0, 433.0] | [1050, 526] |
p03805 | u814781830 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['def dfs(v, N, visited, ret, route):\n if sum(visited) == N:\n return 1\n \n visitable = []\n for pair in route:\n if v in pair:\n if visited[pair[0]] == 0:\n visitable.append(pair[0])\n elif visited[pair[1]] == 0:\n visitable.append(pair[1])\n \n for v in visitable:\n visited[v] = 1\n ret = dfs(v, N, visited, ret, route)\n visited[v] = 0\n \n return ret\n\nN, M = map(int, input().split())\nroute = []\nfor i in range(M):\n a, b = map(int, input().split())\n a, b = a-1, b-1\n route.append([a, b])\nvisited = [0] * N\nvisited[0] = 1\nret = dfs(0, N, visited, 0, route)\nprint(ret)', 'def dfs(v, N, visited, ret, route):\n if sum(visited) == N:\n return ret + 1\n \n visitable = []\n for pair in route:\n if v in pair:\n if visited[pair[0]] == 0:\n visitable.append(pair[0])\n elif visited[pair[1]] == 0:\n visitable.append(pair[1])\n \n for v in visitable:\n visited[v] = 1\n ret = dfs(v, N, visited, ret, route)\n visited[v] = 0\n \n return ret\n\nN, M = map(int, input().split())\nroute = []\nfor i in range(M):\n a, b = map(int, input().split())\n a, b = a-1, b-1\n route.append([a, b])\nvisited = [0] * N\nvisited[0] = 1\nret = dfs(0, N, visited, 0, route)\nprint(ret)'] | ['Wrong Answer', 'Accepted'] | ['s351114008', 's611678975'] | [3064.0, 3064.0] | [43.0, 44.0] | [674, 680] |
p03805 | u814986259 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['\nN,M=map(int,input().split())\nab=[[0]*M]*M\na=[0]*M\nb=[0]*M\n\nreached=[0]*M\n\nfor i in range(M):\n a[i],b[i]=map(int,input().split())\n ab[a[i]][b[i]]=1\n ab[b[i]][a[i]]=1\n \ndef rootCount(pos,N,reached):\n count=0\n prev=0\n for i in range(N):\n if ab[pos][i]==0:\n continue\n if reached[i]==1:\n continue\n reached[i]=1\n count+=rootCount(i,N,reached)\n reached[i]=0\n return(count)\n\nreached[0]=1\ncount=rootCount(0,N,reached)\nprint(count)', 'from itertools import permutation\nN,M=map(int,input().split())\nab=[list(map(int,input().split())) for i in range(M)]\ng=[[False]*N for i in range(N)]\nfor a,b in ab:\n g[a-1][b-1]=True\n g[b-1][a-1]=True\nnodes=[i for i in range(N)]\nans=0\nfor route in permutation(nodes):\n for i in range(N):\n if i == N-1:\n ans+=1\n break\n if g[route[i]][route[i+1]]:\n continue\n else:\n break\nprint(ans)\n \n \n ', 'from itertools import permutations\nN, M = map(int, input().split())\nab = [tuple(map(int, input().split())) for i in range(M)]\nG = [set() for i in range(N)]\n\nfor a, b in ab:\n a -= 1\n b -= 1\n G[a].add(b)\n G[b].add(a)\n\nans = 0\nfor x in permutations(range(1, N)):\n if x[0] in G[0]:\n for i in range(N-1):\n if i < N-2:\n if x[i+1] in G[x[i]]:\n continue\n else:\n break\n else:\n ans += 1\nprint(ans)\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s585595695', 's822907973', 's021340002'] | [3064.0, 3064.0, 3064.0] | [34.0, 18.0, 29.0] | [457, 428, 515] |
p03805 | u820351940 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['n, m = map(int, input().split())\nab = [list(map(int, input().split())) for x in range(m)]\n\nabmap = {}\nfor a, b in ab:\n atarget = abmap.get(a)\n if atarget == None:\n abmap[a] = []\n abmap[a].append(b)\n\n btarget = abmap.get(b)\n if btarget == None:\n abmap[b] = []\n abmap[b].append(a)\n\nque = [[1, abmap[1], []]]\nends = []\nwhile que:\n now, nextnodes, visited = que.pop()\n ends.append(visited)\n visited.append(now)\n for node in nextnodes:\n if node in visited:\n continue\n mvisited = visited[:]\n que.append([node, abmap[node], mvisited])\n\nprint(len(filter(lambda x: len(x) == n, ends)))\n', 'n, m = map(int, input().split())\nab = [list(map(int, input().split())) for x in range(m)]\n\nabmap = {}\nfor a, b in ab:\n atarget = abmap.get(a)\n if atarget == None:\n abmap[a] = []\n abmap[a].append(b)\n\n btarget = abmap.get(b)\n if btarget == None:\n abmap[b] = []\n abmap[b].append(a)\n\nque = [[1, abmap[1], []]]\nends = []\nwhile que:\n now, nextnodes, visited = que.pop()\n ends.append(visited)\n visited.append(now)\n for node in nextnodes:\n if node in visited:\n continue\n mvisited = visited[:]\n que.append([node, abmap[node], mvisited])\n\nprint(len(list(filter(lambda x: len(x) == n, ends))))\n'] | ['Runtime Error', 'Accepted'] | ['s899036268', 's793118935'] | [5236.0, 5236.0] | [42.0, 45.0] | [653, 659] |
p03805 | u822961851 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import itertools\n\ndef resolve():\n n, m = map(int, input().split())\n S = [[0]*m for i in range(m)]\n\n for i in range(m):\n a, b = map(int, input().split())\n S[a-1][b-1] = 1\n S[b-1][a-1] = 1\n\n ans = 0\n for p in itertools.permutations(range(n)):\n if p[0] != 0:\n break;\n tmp = 1\n for i, v in enumerate(p):\n if i > m:\n tmp *= S[p[i+1]][p[i+1]]\n ans += tmp\n\n print(ans)', "import itertools\n\ndef resolve():\n n, m = map(int, input().split())\n S = [[0] * n for i in range(n)]\n\n for i in range(m):\n a, b = map(int, input().split())\n S[a - 1][b - 1] = 1\n S[b - 1][a - 1] = 1\n\n ans = 0\n for p in itertools.permutations(range(n)):\n if p[0] != 0:\n break\n tmp = 1\n for i, v in enumerate(n-1):\n tmp *= S[p[i]][p[i + 1]]\n ans += tmp\n\n print(ans)\n\nif __name__ == '__main__':\n resolve()", 'import itertools\n\ndef resolve():\n n, m = map(int, input().split())\n S = [[0]*m for i in range(m)]\n\n for i in range(m):\n a, b = map(int, input().split())\n S[a-1][b-1] = 1\n S[b-1][a-1] = 1\n\n ans = 0\n for p in itertools.permutations(range(n)):\n if p[0] != 0:\n break;\n tmp = 1\n for i, v in enumerate(p):\n if i > m:\n tmp *= S[p[i]][p[i+1]]\n ans += tmp\n\n print(ans)', "import itertools\n\ndef resolve():\n n, m = map(int, input().split())\n S = [[0]*n for i in range(n)]\n\n for i in range(m):\n a, b = map(int, input().split())\n S[a-1][b-1] = 1\n S[b-1][a-1] = 1\n\n ans = 0\n for p in itertools.permutations(range(n)):\n if p[0] != 0:\n break\n tmp = 1\n for i in range(n-1):\n tmp *= S[p[i]][p[i+1]]\n ans += tmp\n\n print(ans)\n\nif __name__ == '__main__':\n resolve()"] | ['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s135877112', 's723143389', 's732895070', 's980777426'] | [3064.0, 3064.0, 3064.0, 3064.0] | [18.0, 18.0, 19.0, 24.0] | [465, 492, 463, 473] |
p03805 | u823458368 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import numpy as np\nnmax = 8\ngraph = np.array([[False]*nmax]*nmax)\n\nn, m = map(int, input().split())\nfor i in range(m):\n a, b = map(int, input().split())\n graph[a-1][b-1] = graph[b-1][a-1] = True\n \nvisited = [False]*nmax\nvisited[0] = True\n\ndef dfs(v, n, visited): \n all_visited = True\n for i in range(n):\n if visited[i] == False:\n all_visited = False\n\n if all_visited:\n return 1 \n \n ret = 0 \n \n for i in range(n):\n if graph[v][i] == False: \n continue\n if visited[i]: \n continue\n \n visited[i] = True \n ret += dfs(i, n, visited) \n visited[i] = False \n \n return ret\n \ndfs(0, n, visited)', 'import numpy as np\nnmax = 8\ngraph = np.array([[False]*nmax]*nmax)\n \nn, m = map(int, input().split())\nfor i in range(m):\n a, b = map(int, input().split())\n graph[a-1][b-1] = graph[b-1][a-1] = True\n \nvisited = [False]*nmax\nvisited[0] = True\n \ndef dfs(v, n, visited): \n all_visited = True\n for i in range(n):\n if visited[i] == False:\n all_visited = False\n \n if all_visited:\n return 1 \n \n ret = 0 \n \n for i in range(n):\n if graph[v][i] == False: \n continue\n if visited[i]: \n continue\n \n visited[i] = True \n ret += dfs(i, n, visited) \n visited[i] = False \n \n return ret\n \nprint(dfs(0, n, visited))'] | ['Wrong Answer', 'Accepted'] | ['s625782351', 's592328222'] | [12520.0, 12504.0] | [382.0, 388.0] | [932, 942] |
p03805 | u830054172 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['N, M = list(map(int, input().split()))\n\nans = 0\n\ndef dfs(n, visited):\n global ans\n visited.append(n)\n if len(visited) == N:\n ans += 1\n else:\n for i in l[n-1]:\n print("i=", i)\n if i not in visited:\n dfs(i, visited)\n visited.remove(n)\n\nl = [[] for _ in range(N)]\nfor _ in range(M):\n a, b = map(int, input().split())\n l[a-1].append(b)\n l[b-1].append(a) \n\ndfs(1, [])\nprint(ans)\nprint(l)', 'N, M = list(map(int, input().split()))\n\nans = 0\n\ndef dfs(n, visited):\n global ans\n visited.append(n)\n if len(visited) == N:\n ans += 1\n else:\n for i in l[n-1]:\n if i not in visited:\n dfs(i, visited)\n visited.remove(n)\n\nl = [[] for _ in range(N)]\nfor _ in range(M):\n a, b = map(int, input().split())\n l[a-1].append(b)\n l[b-1].append(a) \n\ndfs(1, [])\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s408715409', 's290826704'] | [3956.0, 3064.0] | [78.0, 28.0] | [457, 421] |
p03805 | u839537730 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['N, M = list(map(int, input().split(" ")))\n\ngraph = [list() for i in range(N+1)]\n\nfor i in range(M):\n a, b = list(map(int, input().split(" ")))\n graph[a].append(b)\n graph[b].append(a)\n \ndef DFS(node, prev, visited):\n visited.append(node)\n if len(visited) == N:\n return 1\n \n res = 0\n for edge in graph[node]:\n if edge == prev:\n continue\n elif edge in visited:\n continue\n res += dfs(edge, node, visited)\n \n return res\n\nprint(DFS(1, 0, []))', 'N, M = list(map(int, input().split(" ")))\n\ngraph = [list() for i in range(N+1)]\n\nfor i in range(M):\n a, b = list(map(int, input().split(" ")))\n graph[a].append(b)\n graph[b].append(a)\n \ndef DFS(node, prev, visited):\n visited.append(node)\n if len(visited) == N:\n return 1\n \n res = 0\n for edge in graph[node]:\n if edge == prev:\n continue\n elif edge in visited:\n continue\n res += DFS(edge, node, visited)\n \n return res\n\nprint(DFS(1, 0, []))', 'N, M = list(map(int, input().split(" ")))\n\ngraph = [list() for i in range(N+1)]\n\nfor i in range(M):\n a, b = list(map(int, input().split(" ")))\n graph[a].append(b)\n graph[b].append(a)\n \ndef DFS(node, prev, visited):\n visited.append(node)\n if len(visited) == N:\n return 1\n \n res = 0\n for edge in graph[node]:\n if edge == prev:\n continue\n elif edge in visited:\n continue\n res += dfs(edge, node, visited)\n \n return res\n\nprint(DFS(1, 0, []))', 'N, M = list(map(int, input().split(" ")))\n\ngraph = [list() for i in range(N+1)]\n\nfor i in range(M):\n a, b = list(map(int, input().split(" ")))\n graph[a].append(b)\n graph[b].append(a)\n \ndef DFS(node, prev, visited):\n visited.append(node)\n if len(visited) == N:\n return 1\n \n res = 0\n for edge in graph[node]:\n if edge == prev:\n continue\n elif edge in visited:\n continue\n res += DFS(edge, node, visited[:])\n \n return res\n\nprint(DFS(1, 0, []))'] | ['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s082044547', 's148833629', 's646123245', 's145033161'] | [3064.0, 3064.0, 3064.0, 3064.0] | [17.0, 17.0, 17.0, 28.0] | [523, 523, 523, 526] |
p03805 | u840310460 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['N,M = map(int, input().split())\nL = [list(map(int,input().split())) for _ in range(M)]\ngraph = [[False] * (N + 1) for _ in range(N + 1)]\n#%%\n\nfor i in L:\n graph[i[0]][i[1]] = True\n graph[i[1]][i[0]] = True\n\ngraph[0][1] = True\ngraph[1][0] = True\n#%%\nans = 0\nfor i in permutations(range(1, N + 1)):\n if i[0] != 1:\n continue\n for j in range(1, N):\n if not graph[i[j - 1]][i[j]]:\n break\n else:\n ans += 1 \n\nprint(ans)\n', 'import itertools\n\nN, M = map(int, input().split())\n\npath_matrix = []\n\n\nfor n in range(N):\n path_matrix.append([0] * N)\n\nfor m in range(M):\n paths = [int(i) - 1 for i in input().split()]\n path_matrix[paths[0]][paths[1]] = 1\n path_matrix[paths[1]][paths[0]] = 1\n\nlist_per = list(itertools.permutations(range(N)))\nans = 0\n\nfor i in list_per:\n if i[0] != 0:\n break\n cnt = 1\n for index in range(N - 1):\n cnt *= path_matrix[i[index]][i[index + 1]]\n ans += cnt\n \nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s515633621', 's495203706'] | [3064.0, 8052.0] | [18.0, 38.0] | [459, 534] |
p03805 | u840974625 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import itertools\nimport copy\n\nn, m = map(int, input().split())\nList = [list(map(int, input().split())) for i in range(m)]\ncheck = [0 for _ in range(n)]\nres = 0\n\ndef all_1(res_list):\n leng = len(res_list)\n for i in range(leng):\n if res_list[i] == 0:\n return False\n return True\n\ndef coo(i, check):\n global res\n b = copy.deepcopy(check)\n if b[i-1] == 0:\n b[i-1] = 1\n if all_1(b):\n res += 1\n length = len(List)\n for j in range(length):\n if List[j][0] == i:\n coo(List[j][1], b)\n \n \ncoo(1, check)\nprint(res)', 'import itertools\nimport copy\n\nn, m = map(int, input().split())\nList = [list(map(int, input().split())) for i in range(m)]\ncheck = [0 for _ in range(n)]\nres = 0\n\ndef all_1(res_list):\n leng = len(res_list)\n for i in range(leng):\n if res_list[i] == 0:\n return False\n return True\n\ndef coo(i, check):\n global res\n b = copy.deepcopy(check)\n if b[i-1] == 0:\n b[i-1] = 1\n if all_1(b):\n res += 1\n length = len(List)\n for j in range(length):\n if List[j][0] == i:\n coo(List[j][1], b)\n for j in range(length):\n if List[j][1] == i:\n coo(List[j][0], b)\n \n \ncoo(1, check)\nprint(res)'] | ['Wrong Answer', 'Accepted'] | ['s342888814', 's263847882'] | [3440.0, 3568.0] | [24.0, 855.0] | [616, 715] |
p03805 | u841111730 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['\n\n\nN,M = map(int,input().split())\n\ngraph = [ ]\nfor _ in range(N+1):\n graph.append([])\n\nfor _ in range(M):\n a,b = map(int,input().split())\n graph[a].append(b)\n graph[b].append(a)\n\nvisited = []\nfor _ in range(N+1):\n visited.append(False)\n\n\ndef dfs(dep,cur):\n global N,visited,graph\n\n if dep == N:\n ans += 1\n return 1\n\n ans = 0\n\n for dist in graph[cur]:\n if visited[dist] == False:\n visited[dist] = True\n ans += dfs(dep + 1,dist)\n visited[dist] = False\n return ans\n\n visited[1] = True\n dfs(1,1)\n print(ans)\n', '\n\n\nN,M = map(int,input().split())\n\ngraph = [ ]\nfor _ in range(N+1):\n graph.append([])\n\nfor _ in range(M):\n a,b = map(int,input().split())\n graph[a].append(b)\n graph[b].append(a)\n\nvisited = []\nfor _ in range(N+1):\n visited.append(False)\n\n\ndef dfs(dep,cur):\n global N,visited,graph\n\n if dep == N:\n return 1\n\n ans = 0\n\n for dist in graph[cur]:\n if visited[dist] == False:\n visited[dist] = True\n ans += dfs(dep + 1,dist)\n visited[dist] = False\n return ans\n\nvisited[1] = True\nprint(dfs(1,1))\n'] | ['Runtime Error', 'Accepted'] | ['s483219666', 's696591698'] | [9076.0, 9208.0] | [24.0, 29.0] | [599, 571] |
p03805 | u841623074 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ["def bit_DP(N.Adj):\n dp=[[0]*N for i in range(1<<N)]\n dp[1][0]=1\n for S in range(1<<N):\n for v in range(N):\n if (S&(1<<v))==0:\n continue\n sub=S^(1<<v)\n \n for u in range(N):\n if (sub&(1<<u)) and (Adj[u][v]):\n dp[S][v]+=dp[sub][u]\n ans=sum(dp[(1<<N)-1][u] for u in range(1,N))\n return ans\ndef main():\n N,M=map(int,input().split())\n Adj=[[0]*N for i in range(N)]\n for _ in range(M):\n a,b=map(int,input().split())\n Adj[a-1][b-1]=1\n Adj[b-1][a-1]=1\n ans=bit_dp(N,Adj)\n print(ans)\nif __name__=='__main__':\n main()", "def bit_DP(N,Adj):\n dp=[[0]*N for i in range(1<<N)]\n dp[1][0]=1\n for S in range(1<<N):\n for v in range(N):\n if (S&(1<<v))==0:\n continue\n sub=S^(1<<v)\n \n for u in range(N):\n if (sub&(1<<u)) and (Adj[u][v]):\n dp[S][v]+=dp[sub][u]\n ans=sum(dp[(1<<N)-1][u] for u in range(1,N))\n return ans\ndef main():\n N,M=map(int,input().split())\n Adj=[[0]*N for i in range(N)]\n for _ in range(M):\n a,b=map(int,input().split())\n Adj[a-1][b-1]=1\n Adj[b-1][a-1]=1\n ans=bit_DP(N,Adj)\n print(ans)\nif __name__=='__main__':\n main()"] | ['Runtime Error', 'Accepted'] | ['s448684158', 's569813610'] | [2940.0, 3064.0] | [17.0, 20.0] | [660, 660] |
p03805 | u845620905 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import itertools\nn, m = map(int, input().split())\nd = [[0 for i in range(n)] for j in range(n)]\nfor i in range(m):\n a, b = map(int, input().split())\n a-=1\n b-=1\n d[a][b] = 1\n d[b][a] = 1\nans = 0\n\nnums = [i for i in range(n)]\nfor num in itertools.permutations(nums):\n if(num[0] != 0):\n continue\n flag = True\n for i in range(n - 1):\n flag = False\n break\n if(flag):\n ans += 1\n\nprint(ans)\n', 'import itertools\nn, m = map(int, input().split())\nd = [[0 for i in range(n)] for j in range(n)]\nfor i in range(m):\n a, b = map(int, input().split())\n a-=1\n b-=1\n d[a][b] = 1\n d[b][a] = 1\nans = 0\n\nnums = [i for i in range(n)]\nfor num in itertools.permutations(nums):\n if(num[0] != 0):\n continue\n flag = True\n for i in range(n - 1):\n if(d[num[i]][num[i+1]] != 1):\n flag = False\n break\n if(flag):\n ans += 1\n\nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s899611132', 's097490413'] | [3064.0, 3188.0] | [24.0, 31.0] | [448, 486] |
p03805 | u845650912 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['N,M = map(int,input().split())\n\nA = [list(map(int, input().split())) for i in range(M)]\n\ngraph_data = [[0] * N for i in range(N)]\n\nfor i in range(M):\n if A[i][0] > A[i][1]: A[i][0], A[i][1] = A[i][1], A[i][0]\n graph_data[A[i][0]-1][A[i][1]-1] = graph_data[A[i][1]-1][A[i][0]-1] = 1\n \nvisited = [False] * N\n\ndef dfs(now, depth):\n if visited[now]:\n return 0\n if depth == N - 1:\n return 1\n \n visite[now] = True\n total_path = 0\n for i in range(0,N):\n if graph_data[now][i] == 1: \n total_path += dfs(i, depth + 1)\n visited[now] = False\n \n return total_path\n\nprint(dfs(0,0))', 'N,M = map(int,input().split())\n\nA = [list(map(int, input().split())) for i in range(M)]\n\ngraph_data = [[0] * N for i in range(N)]\n\nfor i in range(M):\n if A[i][0] > A[i][1]: A[i][0], A[i][1] = A[i][1], A[i][0]\n graph_data[A[i][0]-1][A[i][1]-1] = graph_data[A[i][1]-1][A[i][0]-1] = 1\n \nvisited = [False] * N\n\ndef dfs(now, depth):\n if visited[now]:\n return 0\n if depth == N - 1:\n return 1\n \n visited[now] = True\n total_path = 0\n for i in range(0,N):\n if graph_data[now][i] == 1: \n total_path += dfs(i, depth + 1)\n visited[now] = False\n \n return total_path\n\nprint(dfs(0,0))'] | ['Runtime Error', 'Accepted'] | ['s720303112', 's301161629'] | [3192.0, 3064.0] | [18.0, 36.0] | [638, 639] |
p03805 | u858523893 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['from itertools import permutations\n\nn, m = map(int, input().split())\npaths = set()\n\nfor i in range(n) :\n _a, _b = map(int, input().split())\n paths.add((_a, _b))\n paths.add((_b, _a))\n \n# print(sum(all(s in paths for s in zip((1,) + p, p)) for p in permutations(range(2, n + 1))))\n\n', 'from itertools import permutations\n \nn,m=map(int,input().split())\nes=set()\nfor _ in range(m):\n u,v=map(int,input().split())\n u,v=u-1,v-1\n es|={(u,v),(v,u)}', 'from itertools import permutations\n\nn, m = map(int, input().split())\npaths = set()\n\nfor i in range(n) :\n _a, _b = map(int, input().split())\n # paths.add((_a, _b))\n # paths.add((_b, _a))\n \n# print(sum(all(s in paths for s in zip((1,) + p, p)) for p in permutations(range(2, n + 1))))\n\n', 'N, M = map(int, input().split())\na, b = [], []\n\nfor i in range(M) :\n _a, _b = map(int, input().split())\n \n a.append(_a - 1)\n b.append(_b - 1)\n\nzero_mask = "".join([\'0\' for x in range(N)])\nfull_mask = "".join([\'1\' for x in range(N)])\npaths_cnt = 0\npaths_set = set()\n\ndef do_mask(m, idx) :\n newmask = m[:idx] + \'1\' + m[idx + 1:]\n return newmask\n\ndef dfs(m, idx) :\n global paths_cnt\n \n # print("DBG, do dfs with : ", m, idx)\n \n newmask = do_mask(m, idx)\n \n if newmask == full_mask :\n paths_cnt += 1\n else :\n for i in range(N) :\n # print("DBG2 : ", idx != i, newmask[i] != \'1\', (idx, i) in paths_set, (idx, i))\n if idx != i and newmask[i] != \'1\' and (idx, i) in paths_set:\n dfs(newmask, i)\n\nfor i in range(M) :\n paths_set.add((a[i], b[i]))\n paths_set.add((b[i], a[i]))\n \ndfs(zero_mask, 0)\nprint(paths_cnt)'] | ['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s672372895', 's708581512', 's754752454', 's087150706'] | [3060.0, 3060.0, 3060.0, 3064.0] | [17.0, 18.0, 17.0, 35.0] | [292, 164, 296, 942] |
p03805 | u863442865 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ["res = 0\ndef main():\n import sys\n #input = sys.stdin.readline\n sys.setrecursionlimit(10000000)\n from collections import Counter, deque\n #from collections import defaultdict\n from itertools import combinations\n #from itertools import accumulate, product, permutations\n from math import floor, ceil\n\n #mod = 1000000007\n\n\n N,M = map(int, input().split())\n g = [[] for _ in range(N)]\n for _ in range(M):\n a,b = map(int, input().split())\n g[a-1].append(b-1)\n g[b-1].append(a-1)\n\n visited = [0]*N\n\n def dfs(node):\n \tglobal res\n visited[node]=1\n if all(visited):\n res += 1\n return\n for n_node in g[node]:\n if not visited[n_node]:\n dfs(n_node)\n visited[n_node] = 0\n dfs(0)\n print(res)\n\nif __name__ == '__main__':\n main()", "res = 0\ndef main():\n import sys\n #input = sys.stdin.readline\n sys.setrecursionlimit(10000000)\n from collections import Counter, deque\n #from collections import defaultdict\n from itertools import combinations\n #from itertools import accumulate, product, permutations\n from math import floor, ceil\n\n #mod = 1000000007\n\n\n N,M = map(int, input().split())\n g = [[] for _ in range(N)]\n for _ in range(M):\n a,b = map(int, input().split())\n g[a-1].append(b-1)\n g[b-1].append(a-1)\n\n visited = [0]*N\n\n def dfs(node):\n global res\n visited[node]=1\n if all(visited):\n res += 1\n return\n for n_node in g[node]:\n if not visited[n_node]:\n dfs(n_node)\n visited[n_node] = 0\n dfs(0)\n print(res)\n\nif __name__ == '__main__':\n main()\n"] | ['Runtime Error', 'Accepted'] | ['s503713212', 's801780613'] | [3060.0, 3316.0] | [18.0, 27.0] | [884, 886] |
p03805 | u872887731 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['def dfs(v,N,visit_list):\n\n all_visit = True\n\n for i in range(N):\n if visit_list[i] == False:\n all_visit = False\n \n if all_visit:\n return 1\n\n ret = 0\n\n for k in range(N):\n if Graph[v][k] == False:\n continue\n if visit_list[k] :\n continue\n \n visit_list[k] = True\n ret += dfs(k,N,visit_list)\n visit_list[k] = False\n return ret\n\nvisit_list = [False for i in range(N)]\nvisit_list[0] = True\nprint(dfs(0,N,visit_list))\n \n\n', 'N,M = map(int,input().split())\npat = [[int(i) for i in input().split()] for _ in range(M)]\nGraph = [[0 for i in range(N)] for _ in range(N)]\nfor i,j in pat:\n Graph[i-1][j-1] = 1\n Graph[j-1][i-1] = 1\n\ndef dfs(v,N=N,visit_list):\n\n all_visit = True\n\n for i in range(N):\n if visit_list[i] == False:\n all_visit = False\n \n if all_visit:\n return 1\n\n ret = 0\n\n for k in range(N):\n if Graph[v][k] == False:\n continue\n if visit_list[k] :\n continue\n \n visit_list[k] = True\n ret += dfs(k,N,visit_list)\n visit_list[k] = False\n return ret\n\nvisit_list = [False for i in range(N)]\nvisit_list[0] = True\nprint(dfs(0,N,visit_list))\n \n\n', 'N,M = map(int,input().split())\npat = [[int(i) for i in input().split()] for _ in range(M)]\nGraph = [[0 for i in range(N)] for _ in range(N)]\nfor i,j in pat:\n Graph[i-1][j-1] = 1\n Graph[j-1][i-1] = 1\n\ndef dfs(v,N,visit_list):\n\n all_visit = True\n\n for i in range(N):\n if visit_list[i] == False:\n all_visit = False\n \n if all_visit:\n return 1\n\n ret = 0\n\n for k in range(N):\n if Graph[v][k] == False:\n continue\n if visit_list[k] :\n continue\n \n visit_list[k] = True\n ret += dfs(k,N,visit_list)\n visit_list[k] = False\n return ret\n\nvisit_list = [False for i in range(N)]\nvisit_list[0] = True\nprint(dfs(0,N,visit_list))\n \n\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s191065026', 's283573263', 's584845732'] | [3064.0, 3064.0, 3064.0] | [17.0, 17.0, 37.0] | [527, 735, 733] |
p03805 | u879302598 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['from itertools import permutations\n\ndef f(n, m, uu, vv):\n a = [[0] * n for _ in range(n)]\n for u, v in zip(uu, vv):\n a[u][v] = 1\n a[v][u] = 1\n res = 0\n for p in permutations(range(n)):\n if p[0] != 0:\n break\n ok = True\n for i in range(n-1):。\n if a[p[i][p[i+1]] == 0:\n ok = False\n break\n if ok:\n res += 1\n return res\n\n\nn,m = map(int,input().split())\na = []\nb = []\nfor i in range(m):\n _a, _b = map(int, input().split())\n _a -= 1\n _b -= 1\n a.append(_a)\n b.append(_b)\n\nprint(f(n, m, a, b))\n', 'from itertools import permutations\n\ndef f(n, m, uu, vv):\n a = [[0] * n for _ in range(n)]\n for u, v in zip(uu, vv):\n \n a[u][v] = 1\n a[v][u] = 1\n \n res = 0\n for p in permutations(range(n)):\n if p[0] != 0:\n break\n \n ok = True\n for i in range(n-1):\n if a[p[i]][p[i+1]] == 0:\n ok = False\n break\n if ok:\n res += 1\n return res\n\n\nn,m = map(int,input().split())\na = []\nb = []\n\nfor i in range(m):\n _a, _b = map(int, input().split())\n _a -= 1\n _b -= 1\n a.append(_a)\n b.append(_b)\n\nprint(f(n, m, a, b))\n'] | ['Runtime Error', 'Accepted'] | ['s380031187', 's480640257'] | [3064.0, 3064.0] | [18.0, 24.0] | [622, 637] |
p03805 | u879870653 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['N,M = map(int,input().split())\n\nL = [[] for i in range(N)]\n\nfor i in range(M) :\n a,b = map(int,input().split())\n a -= 1\n b -= 1\n \n L[a].append(b)\n L[b].append(a)\n\nP = permutations([0] + [i for i in range(1,N)])\n\nans = 0\n\nfor perm in P :\n visited = [0 for i in range(N)]\n visited[0] = 1\n for i in range(N-1) :\n if perm[i+1] not in L[perm[i]] :\n break\n \n if visited[perm[i+1]] :\n break\n \n visited[perm[i+1]] = 1\n \n if sum(visited) == N :\n ans += 1\n\nprint(ans)\n', 'from itertools import permutations as pm\n\nN,M = map(int,input().split())\n\nMatrix = [[False for i in range(N)] for j in range(N)] \n\nfor i in range(N) :\n Matrix[i][i] = True\n\nfor i in range(N) :\n row,column = map(int,input().split())\n Matrix[row-1][column-1] = True\n Matrix[column-1][row-1] = True\n \narange = list(range(2,N+1))\nans = 0\nfor pm in permutations(arange) :\n P = [1] + list(pm)\n for row,column in zip(P,P[1:]) :\n if not Matrix[row-1][column-1] :\n break\n else :\n ans += 1\nprint(ans)\n', 'from itertools import permutations\n\nN,M = map(int,input().split())\n\nA = [[0]*N for i in range(N)]\n\nfor i in range(M) :\n u,v = map(int,input().split())\n u -= 1\n v -= 1\n \n A[u][v] = 1\n A[v][u] = 1\n\nran = list(range(1,N))\n\nP = list(permutations(ran))\n\nans = 0\n\nfor perm in P :\n perm = list(perm)\n \n for u,v in zip([0]+perm, perm) :\n if not A[u][v] :\n break\n \n else :\n ans += 1\n\nprint(ans)\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s048574096', 's476909995', 's101407806'] | [3064.0, 3064.0, 3572.0] | [17.0, 18.0, 28.0] | [556, 553, 448] |
p03805 | u880128069 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import itertools\n\nn,m = map(int,input().split())\n\npath = [[False] * n for i in range(n)]\n\nfor i in range(m):\n a,b = map(int,input().split())\n a -= 1\n b -= 1\n path[a][b] = True\n path[b][a] = True\n \nans = 0\n\n\nfor i in itertools.permutations(range(n),n):\n \n if i[0] == 0:\n \n for j in range(n):\n \n if j == n-1:\n ans += 1\n break\n \n if not path[i[j][j+1]]:\n break\n \nprint(ans)', 'import itertools\n \nn,m = map(int,input().split())\n \npath = [[False] * n for i in range(n)]\n \nfor i in range(m):\n a,b = map(int,input().split())\n a -= 1\n b -= 1\n path[a][b] = True\n path[b][a] = True\n \nans = 0\n \n\nfor i in itertools.permutations(range(n),n):\n \n if i[0] == 0:\n \n for j in range(n):\n \n if j == n-1:\n ans += 1\n break\n \n if not path[i[j]][i[j+1]]:\n break\n \nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s374202184', 's919411007'] | [3064.0, 3064.0] | [18.0, 35.0] | [665, 672] |
p03805 | u884323674 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['N, M = map(int, input().split())\nab = [[int(i) for i in input().split()] for j in range(M)]\n\nG = [[] for i in range(N)]\nfor i in range(M):\n a, b = ab[i]\n G[a-1].append(b-1)\n G[b-1].append(a-1)\n\ndef rec(v, memo):\n memo[v] = 1\n\n if -1 not in memo:\n memo[v] -1\n return 1\n\n count = 0\n for next_v in G[v]:\n if memo[next_v] == -1:\n count += rec(next_v, memo)\n\n memo[v] = -1\n return count\n\nmemo = [-1 for i in range(N)]\nprint(rec(1, memo))', 'import itertools\n\nN, M = map(int, input().split())\nab = [[int(i) for i in input().split()] for j in range(M)]\n\nG = [[] for i in range(N)]\nfor i in range(M):\n a, b = ab[i]\n G[a-1].append(b-1)\n G[b-1].append(a-1)\n\nls = [i for i in range(1, N)]\nans = 0\nfor route in itertools.permutations(ls, N-1):\n pre = 0\n for i in range(N-1):\n next_v = route[i]\n if next_v not in G[pre]:\n break\n pre = next_v\n else: ans += 1\n\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s848375037', 's602298193'] | [3064.0, 3064.0] | [17.0, 29.0] | [491, 470] |
p03805 | u886655280 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ["\n\nimport copy\n\n\nN, M = map(int, input().split())\n\n\n\nGraph_list = [[] for i in range(N)]\n\n\nfor i in range(M):\n a, b = map(int, input().split())\n a += -1\n b += -1\n\n \n Graph_list[a].append(b)\n Graph_list[b].append(a)\n\nans_count = 0\nthrowgh_point_list = [-1 for i in range(N)]\n\ndef dfs(i, current, throwgh_point_list, ans_point_list): \n \n if i >= N:\n \n if throwgh_point_list in ans_point_list:\n print('カウント済み')\n print(throwgh_point_list)\n return\n\n \n \n if set(throwgh_point_list) == set(list(range(N))):\n global ans_count\n ans_count += 1\n ans_point_list.append(copy.copy(throwgh_point_list))\n print(throwgh_point_list)\n return\n\n for j in range(len(Graph_list[current])):\n \n throwgh_point_list[i] = current\n\n \n dfs(i + 1, Graph_list[current][j], throwgh_point_list, ans_point_list)\n\ndfs(0, 0, throwgh_point_list, [])\nprint(ans_count)", '\n\nimport copy\nimport sys\ninput = sys.stdin.readline\n\n\nN, M = map(int, input().split())\n\n\n\nGraph_list = [[] for i in range(N)]\n\n\nfor i in range(M):\n a, b = map(int, input().split())\n a += -1\n b += -1\n\n \n Graph_list[a].append(b)\n Graph_list[b].append(a)\n\nans_count = 0 \nvisited = [False] * N\nvisited[0] = True\n\ndef dfs(i, current, visited): \n \n if i >= N-1:\n\n \n \n if all(visited):\n global ans_count\n ans_count += 1\n return \n return \n\n for j in Graph_list[current]:\n if visited[j] == False:\n \n visited[j] = True\n \n dfs(i + 1, j, visited)\n\ndfs(0, 0, visited)\nprint(ans_count)', '\n\nimport copy\n\n\nN, M = map(int, input().split())\n\n\n\nGraph_list = [[] for i in range(N)]\n\n\nfor i in range(M):\n a, b = map(int, input().split())\n a += -1\n b += -1\n\n \n Graph_list[a].append(b)\n Graph_list[b].append(a)\n\nans_count = 0\nthrowgh_point_list = [-1 for i in range(N)]\n\ndef dfs(i, current, throwgh_point_list, ans_point_list): \n \n if i >= N:\n \n if throwgh_point_list in ans_point_list:\n return\n\n \n \n if set(throwgh_point_list) == set(list(range(N))):\n global ans_count\n ans_count += 1\n ans_point_list.append(copy.copy(throwgh_point_list))\n print(throwgh_point_list)\n return\n\n for j in range(len(Graph_list[current])):\n \n throwgh_point_list[i] = current\n\n \n dfs(i + 1, Graph_list[current][j], throwgh_point_list, ans_point_list)\n\ndfs(0, 0, throwgh_point_list, [])\nprint(ans_count)', '\n\nimport copy\nimport sys\ninput = sys.stdin.readline\n\n\nN, M = map(int, input().split())\n\n\n\nGraph_list = [[] for i in range(N)]\n\n\nfor i in range(M):\n a, b = map(int, input().split())\n a += -1\n b += -1\n\n \n Graph_list[a].append(b)\n Graph_list[b].append(a)\n\nans_count = 0 \nvisited = [False] * N\nvisited[0] = True\n\ndef dfs(i, current, visited): \n \n if i >= N-1:\n\n \n if all(visited):\n global ans_count\n ans_count += 1\n return \n return \n\n for j in Graph_list[current]:\n if visited[j] == False:\n \n visited[j] = True\n \n dfs(i + 1, j, visited)\n\n visited[j] = False\n\ndfs(0, 0, visited)\nprint(ans_count)'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s317121352', 's417975798', 's589220149', 's009495814'] | [3700.0, 3444.0, 3572.0, 3444.0] | [2104.0, 22.0, 2104.0, 29.0] | [1487, 1125, 1409, 1128] |
p03805 | u905582793 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['from itertools import permutations\nn,m=map(int,input().split())\nside=[[] for _ in range(n+1)]\nfor i in range(m):\n a,b=map(int,input().split())\n side[a].append(b)\n side[b].append(a)\nroute=[i for i in range(2,n+1)]\nans=0\nfor x in permutations(route):\n x=(1)+x\n for i in range(n-1):\n if x[i+1] not in side[x[i]]:\n break\n else:\n ans+=1\nprint(ans)', 'from itertools import permutations\nn,m=map(int,input().split())\nside=[[] for _ in range(n+1)]\nfor i in range(m):\n a,b=map(int,input().split())\n side[a].append(b)\n side[b].append(a)\nroute=[i for i in range(2,n+1)]\nans=0\nfor x in permutations(route):\n x=list(x)\n x.insert(0,1)\n for i in range(n-1):\n if x[i+1] not in side[x[i]]:\n break\n else:\n ans+=1\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s586032548', 's118473191'] | [3064.0, 3064.0] | [18.0, 31.0] | [359, 377] |
p03805 | u912862653 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import itertools\n\ndef is_edge_exists(node1, node2, edges):\n\tfor edge in edges:\n\t\tif node1 in edge and node2 in edge:\n\t\t\treturn True\n\treturn False\n\ndef route_count(route, edges):\n\tif route[0]==1:\n\t\treturn 0\n\tfor i in range(len(route)-1):\n\t\tif not is_edge_exists(route[i], route[i+1], edges):\n\t\t\treturn 0\n\treturn 1\n\nN, M = map(int, input().split())\nedges = [list(map(int, input().split())) for i in range(M)]\nnodes = [i+1 for i in range(N)]\nroutes = list(itertools.permutations(nodes))\n\nans = 0\nfor route in routes:\n\tans += route_count(route, edges)\nprint(ans)', 'import itertools\n\ndef is_edge_exists(node1, node2, edges):\n\tfor edge in edges:\n\t\tif node1 in edge and node2 in edge:\n\t\t\treturn True\n\treturn False\n\ndef route_count(route, edges):\n\tif route[0]!=1:\n\t\treturn 0\n\tfor i in range(len(route)-1):\n\t\tif not is_edge_exists(route[i], route[i+1], edges):\n\t\t\treturn 0\n\treturn 1\n\nN, M = map(int, input().split())\nedges = [list(map(int, input().split())) for i in range(M)]\nnodes = [i+1 for i in range(N)]\nroutes = list(itertools.permutations(nodes))\n\nans = 0\nfor route in routes:\n\tans += route_count(route, edges)\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s906275437', 's952388313'] | [10100.0, 8052.0] | [301.0, 78.0] | [558, 558] |
p03805 | u934868410 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['from collections import defaultdict\nimport itertools\n\nn,m = map(int,input().split())\ne = [[False]*n for _ in range(n)]\n\nfor _ in range(m):\n a,b = map(int,input().split())\n e[a-1][b-1] = True\n e[b-1][a-1] = True\n\nans = 0\nl = [i for i in range(1,n)]\nfor p in itertools.permutations(l):\n p = [0] + p\n reach = 1\n for i in range(n-1):\n if not e[p[i]][p[i+1]]:\n reach = 0\n break\n ans += reach\n\nprint(ans)', 'import itertools\nn,m = map(int,input().split())\ne = [[False]*n for _ in range(n)]\nfor _ in range(m):\n a,b = map(int,input().split())\n e[a-1][b-1] = True\n e[b-1][a-1] = True\n\nans = 0\nl = [i for i in range(1,n)]\nfor p in itertools.permutations(l):\n p = [0] + list(p)\n reach = 1\n for i in range(n-1):\n if not e[p[i]][p[i+1]]:\n reach = 0\n break\n ans += reach\n\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s732895564', 's840028488'] | [3316.0, 3064.0] | [22.0, 29.0] | [418, 386] |
p03805 | u936985471 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['n,m=map(int,input().split())\nnexts=[None for i in range(n)]\nfor i in range(n):\n a,b=map(int,input().split())\n a,b=a-1,b-1\n if nexts[a]==None:\n nexts[a]=[b]\n else:\n nexts[a].append(b)\n\nans=0\nstack=[]\nstack.append([0,set()])\nwhile stack:\n node=stack.pop()\n v=node[0]\n seen=node[1]\n seen.add(v)\n if len(seen)==n:\n ans+=1\n continue\n childs=nexts[v]\n if childs:\n for child in (set(childs)-seen):\n stack.append(child,seen)\n \nprint(ans)', 'n,m=map(int,input().split())\nnexts=[None for i in range(n)]\nfor i in range(n):\n a,b=map(int,input().split())\n a,b=a-1,b-1\n if nexts[a]==None:\n nexts[a]=[b]\n else:\n nexts[a].append(b)\n if nexts[b]==None:\n nexts[b]=[a]\n else:\n nexts[b].append(a)\n\nans=0\nstack=[]\nstack.append([0,[]])\nwhile stack:\n node=stack.pop()\n v=node[0]\n seen=node[1]\n seen.append(v)\n if len(seen)==n:\n ans+=1\n continue\n childs=nexts[v]\n if childs:\n for child in (set(childs)-set(seen)):\n stack.append([child,seen])\n \nprint(ans)\n', 'n,m=map(int,input().split())\nnexts=[None for i in range(n)]\nfor i in range(n):\n a,b=map(int,input().split())\n a,b=a-1,b-1\n if nexts[a]==None:\n nexts[a]=[b]\n else:\n nexts[a].append(b)\n if nexts[b]==None:\n nexts[b]=[a]\n else:\n nexts[b].append(a)\n\nans=0\nstack=[]\nstack.append([0,[]])\nwhile stack:\n node=stack.pop()\n v=node[0]\n seen=node[1]\n seen.append(v)\n if len(seen)==n:\n ans+=1\n continue\n childs=nexts[v]\n if childs:\n for child in (set(childs)-seen):\n stack.append([child,seen])\n \nprint(ans)\n', 'import sys\nreadline = sys.stdin.readline\n\nN,M = map(int,readline().split())\nG = [[] for i in range(N)]\n\nfor i in range(M):\n a,b = map(int,readline().split())\n G[a - 1].append(b - 1)\n G[b - 1].append(a - 1)\n\nstack = []\nstack.append([0, set()])\nans = 0\nwhile stack:\n v, visited = stack.pop()\n visited.add(v)\n if len(visited) == N:\n ans += 1\n continue\n for child in G[v]:\n if child in visited:\n continue\n visited_c = visited.copy()\n stack.append([child, visited_c])\n \nprint(ans)'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s045993711', 's191965530', 's351491827', 's124077703'] | [3188.0, 3064.0, 3064.0, 9100.0] | [19.0, 17.0, 17.0, 36.0] | [461, 538, 533, 503] |
p03805 | u941753895 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy\n\nsys.setrecursionlimit(10**7)\ninf=10**20\nmod=10**9+7\ndd=[(-1,0),(0,1),(1,0),(0,-1)]\nddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]\n\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\n# def LF(): return [float(x) for x in sys.stdin.readline().split()]\ndef I(): return int(sys.stdin.readline())\ndef F(): return float(sys.stdin.readline())\ndef LS(): return sys.stdin.readline().split()\ndef S(): return input()\n\nN,M=LI()\ngraph=[[N]*8 for _ in range(N)]\n\nfor _ in range(M):\n a,b=LI()\n a-=1\n b-=1\n graph[a][b]=True\n graph[b][a]=True\n\ndef dfs(v,visited):\n all_visited=True\n for i in range(N):\n if not visited[i]:\n all_visited=False\n if all_visited:\n return 1\n\n for i in range(N):\n if not graph[v][i]:\n continue\n if visited[i]:\n continue\n ret=0\n visited[i]=True\n ret+=dfs(i,visited)\n visited[i]=False\n\n return ret\n\nvisited=[False]*N\nvisited[0]=True\nprint(dfs(0,visited))\n', 'import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy\n\nsys.setrecursionlimit(10**7)\ninf=10**20\nmod=10**9+7\ndd=[(-1,0),(0,1),(1,0),(0,-1)]\nddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]\n\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\n# def LF(): return [float(x) for x in sys.stdin.readline().split()]\ndef I(): return int(sys.stdin.readline())\ndef F(): return float(sys.stdin.readline())\ndef LS(): return sys.stdin.readline().split()\ndef S(): return input()\n\nN,M=LI()\ngraph=[[False]*8 for _ in range(8)]\n\nfor _ in range(M):\n a,b=LI()\n a-=1\n b-=1\n graph[a][b]=True\n graph[b][a]=True\n\ndef dfs(v,visited):\n all_visited=True\n for i in range(N):\n if not visited[i]:\n all_visited=False\n if all_visited:\n return 1\n\n ret=0\n for i in range(N):\n if not graph[v][i]:\n continue\n if visited[i]:\n continue\n visited[i]=True\n ret+=dfs(i,visited)\n visited[i]=False\n\n return ret\n\nvisited=[False]*N\nvisited[0]=True\nprint(dfs(0,visited))\n'] | ['Wrong Answer', 'Accepted'] | ['s662500815', 's826862484'] | [10668.0, 10720.0] | [54.0, 52.0] | [1010, 1012] |
p03805 | u944643608 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['\nN, M = map(int,input().split())\ngraph = [[] for j in range(N)]\nfor i in range(M):\n a, b = map(int,input().split())\n graph[a-1].append(b-1)\n graph[b-1].append(a-1)\njudge = [False]*N\n\ndef dfs(v,judge):\n if all(judge):\n return 1\n res = 0\n for nv in graph(v):\n if judge[nv] == True:\n continue \n judge[nv] = True\n res += dfs(nv,judge)\n judge[nv] = False\n return res\nprint(dfs(0,judge))', '\nN, M = map(int,input().split())\ngraph = [[] for j in range(N)]\nfor i in range(M):\n a, b = map(int,input().split())\n graph[a-1].append(b-1)\n graph[b-1].append(a-1)\njudge = [False]*N\njudge[0] = True\n\ndef dfs(v,judge):\n if all(judge):\n return 1\n res = 0\n for nv in graph[v]:\n if judge[nv]:\n continue \n judge[nv] = True\n res += dfs(nv,judge)\n judge[nv] = False\n return res\nprint(dfs(0,judge))\n'] | ['Runtime Error', 'Accepted'] | ['s148110614', 's825774012'] | [3064.0, 3064.0] | [18.0, 23.0] | [525, 534] |
p03805 | u945181840 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['from itertools import permutations\nimport sys\ninput = sys.stdin.readline\n\nN, M = map(int, input().split())\n\nver = [[] for _ in range(N)]\n\nprint(ver)\n\nfor i in range(M):\n a, b = map(int, input().split())\n a, b = a - 1, b - 1\n ver[a].append(b)\n ver[b].append(a)\n\nans = 0\n\nfor i in permutations(range(1, N)):\n here = 0\n for j in i:\n if j not in ver[here]:\n break\n here = j\n else:\n ans += 1\n\nprint(ans)', 'from itertools import permutations\nimport sys\ninput = sys.stdin.readline\n\nN, M = map(int, input().split())\n\nver = [[] for _ in range(N)]\n\n\nfor i in range(M):\n a, b = map(int, input().split())\n a, b = a - 1, b - 1\n ver[a].append(b)\n ver[b].append(a)\n\nans = 0\n\nfor i in permutations(range(1, N)):\n here = 0\n for j in i:\n if j not in ver[here]:\n break\n here = j\n else:\n ans += 1\n\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s771574927', 's847967728'] | [3064.0, 3064.0] | [25.0, 25.0] | [502, 491] |
p03805 | u946386741 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['N, M = map(int, input().split())\n\nl = []\n\nfor i in range(N):\n l.append(list(map(int, input().split())))\n\nlis = [[] for i in range(N)]\n\nfor i in range(N):\n lis[l[i][0] - 1].append(l[i][1])\n lis[l[i][1] - 1].append(l[i][0])\n\nprint(lis)\n\n\n# list = [[0 for c in range(M)] for r in range(N)]\n#\n\n# tmp_n, tmp_m = map(int, input().split())\n# list[tmp_n - 1][tmp_m - 1] = 1\n#\n#\n\n# results = [[0 for c in range(M)] for r in range(N)]\n\n# print(i,j)\n# return results\n\n\n\n\n# def travel(now, nextnodes, visited):\n# ends.append(visited)\n# visited.append(now + 1)\n# for node in nextnodes:\n# if node in visited:\n# continue\n# travel(node - 1, lis[node - 1], visited[:])\n#\n#\n# travel(0, lis[0], [])\n\nque = [[0, lis[0], []]]\nends = []\nwhile que:\n now, nextnodes, visited = que.pop()\n ends.append(visited)\n visited.append(now + 1)\n for node in nextnodes:\n if node in visited:\n continue\n que.append([node - 1, lis[node - 1], visited[:]])\n\nprint(len(list(filter(lambda i: len(i) is 3, ends))))', 'N, M = map(int, input().split())\n\nl = []\n\nfor i in range(N):\n l.append(list(map(int, input().split())))\n\nlis = [[] for i in range(N)]\n\nfor i in range(N):\n lis[l[i][0] - 1].append(l[i][1])\n lis[l[i][1] - 1].append(l[i][0])\n\nprint(lis)\n\n\n# list = [[0 for c in range(M)] for r in range(N)]\n#\n\n# tmp_n, tmp_m = map(int, input().split())\n# list[tmp_n - 1][tmp_m - 1] = 1\n#\n#\n\n# results = [[0 for c in range(M)] for r in range(N)]\n\n# print(i,j)\n# return results\n\n\n\n\n# def travel(now, nextnodes, visited):\n# ends.append(visited)\n# visited.append(now + 1)\n# for node in nextnodes:\n# if node in visited:\n# continue\n# travel(node - 1, lis[node - 1], visited[:])\n#\n#\n# travel(0, lis[0], [])\n\nque = [[0, lis[0], []]]\nends = []\nwhile que:\n now, nextnodes, visited = que.pop()\n ends.append(visited)\n visited.append(now + 1)\n for node in nextnodes:\n if node in visited:\n continue\n que.append([node - 1, lis[node - 1], visited[:]])\n\nprint(len(list(filter(lambda i: len(i) is 3, ends))))\n', 'N, M = map(int, input().split())\n\nl = []\n\nfor i in range(M):\n l.append(list(map(lambda x: int(x) - 1, input().split())))\n\nlis = [[] for i in range(N)]\n\nfor i in range(M):\n lis[l[i][0]].append(l[i][1])\n lis[l[i][1]].append(l[i][0])\n\n\n\n# list = [[0 for c in range(M)] for r in range(N)]\n#\n\n# tmp_n, tmp_m = map(int, input().split())\n# list[tmp_n - 1][tmp_m - 1] = 1\n#\n#\n\n# results = [[0 for c in range(M)] for r in range(N)]\n\n# print(i,j)\n# return results\n\n\n\n\n# def travel(now, nextnodes, visited):\n# ends.append(visited)\n# visited.append(now + 1)\n# for node in nextnodes:\n# if node in visited:\n# continue\n# travel(node - 1, lis[node - 1], visited[:])\n#\n#\n# travel(0, lis[0], [])\n\nque = [[0, lis[0], []]]\nends = []\n\nwhile que:\n now, nextnodes, visited = que.pop()\n ends.append(visited)\n visited.append(now)\n for node in nextnodes:\n if node in visited:\n continue\n que.append([node, lis[node], visited[:]])\n\nprint(len(list(filter(lambda ii: len(ii) is N, ends))))\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s527979494', 's784866310', 's892525531'] | [3064.0, 3064.0, 5236.0] | [18.0, 17.0, 46.0] | [1200, 1201, 1190] |
p03805 | u957872856 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import itertools\n\nN, M = map(int,input().split())\nedges = {tuple(sorted(map(int,input().split()))) for i in range(M)}\nprint(edges)\nans = 0\nnum = 0\nfor i in itertools.permutations(range(2,N+1)):\n #print(i)\n l = [1] + list(i)\n for edge in zip(l,l[1:]):\n #print(edge)\n if tuple(sorted(edge)) in edges:\n num += 1\n if num == N-1:\n ans += 1\n num = 0\n #print(l,l[1:])\n #ans += sum(1 for edge in zip(l,l[1:]) if tuple(sorted(edge)) in edges)==N-1\n #print(ans)\nprint(ans) \n', 'import itertools\nn, m = map(int,input().split())\nedges = {tuple(sorted(map(int,input().split()))) for i in range(m)}\n#print(edges)\nans = 0\na = 0\nfor i in itertools.permutations(range(2, n+1), n-1):\n l = [1] + list(i)\n #print(l, l[1:])\n ans += sum(1 for edge in zip(l,l[1:]) if tuple(sorted(edge)) in edges) == n-1\n \nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s556037695', 's676863984'] | [3064.0, 3064.0] | [45.0, 43.0] | [583, 408] |
p03805 | u958958520 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import sys\nn,m = map(int,input().split())\ngraph = [list(input().split(" ")) for i in range(n)]\n\nresult=0\n\ndef dfs(a, list, graph, result):\n print(list)\n if len(list) == n:\n result = result + 1\n\n for g in graph:\n if g[0] == a and g[1] not in list:\n list.append(g[1])\n result = dfs(g[1], list, graph, result)\n if g[1] == a and g[0] not in list:\n list.append(g[0])\n result = dfs(g[0], list, graph, result)\n\n return result\n\nfor g in graph:\n list = []\n if g[0] == "1":\n list.append(1)\n result += dfs("1", list, graph, 0)\n\nprint(result)\n', 'import sys\nn,m = map(int,input().split())\ngraph = [list(input().split(" ")) for i in range(n)]\n\nresult=0\n\ndef dfs(a, list, graph, result):\n print(list)\n if len(list) == n:\n result = result + 1\n\n for g in graph:\n if g[0] == a and g[1] not in list:\n list.append(g[1])\n result = dfs(g[1], list, graph, result)\n if g[1] == a and g[0] not in list:\n list.append(g[0])\n result = dfs(g[0], list, graph, result)\n\n return result\n\nfor g in graph:\n list = []\n if g[0] == "1":\n list.append(1)\n result += dfs("1", list, graph, 0)\n\nprint(result)\n', 'N, M = map(int, input().split())\nadj_matrix = [[0]* N for _ in range(N)]\n\nfor i in range(M):\n a, b = map(int, input().split())\n adj_matrix[a-1][b-1] = 1\n adj_matrix[b-1][a-1] = 1\n\ndef dfs(v, used):\n if not False in used:\n return 1\n \n ans = 0\n for i in range(N):\n if not adj_matrix[v][i]:\n continue\n if used[i]:\n continue\n \n used[i] = True\n ans += dfs(i, used)\n used[i] = False\n \n return ans\n\nused = [False] * N\nused[0] = True\n\nprint(dfs(0, used))'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s507506682', 's876791595', 's181140998'] | [9224.0, 9220.0, 9136.0] | [30.0, 27.0, 32.0] | [573, 573, 544] |
p03805 | u968846084 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['n,m=map(int,input().split())\nA=[["."]*n for i in range(n)]\nB=[["."]*m for i in range(m)]\nfor i in range(n):\n A[i]=list(input())\nfor i in range(m):\n B[i]=list(input())\nfor i in range(n-m+1):\n for j in range(n-m+1):\n a=0\n for x in range(m):\n for y in range(m):\n if A[i+x][j+y]!=B[x][y]:\n a=1\n break\n if a==0:\n print("Yes")\n exit()\nprint("No")', 'import itertools\nn,m=map(int,input().split())\nG=[[0]*n for i in range(n)]\nfor i in range(m):\n a,b=map(int,input().split())\n G[a-1][b-1]=1\n G[b-1][a-1]=1\nS=""\nfor i in range(1,n):\n S=S+str(i)\nans=0\nfor x in itertools.permutations(S):\n a=0\n if G[0][int(x[0])]==0:\n a=1\n for i in range(n-2):\n if G[int(x[i])][int(x[i+1])]==0:\n a=1\n if a==0:\n ans=ans+1\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s950695826', 's200454856'] | [3064.0, 3064.0] | [18.0, 40.0] | [392, 381] |
p03805 | u981206782 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import itertools\n\nn,m=map(int,input().split())\ng=[list(map(int,input().split())) for _ in range(m)]\nv=list(itertools.permutations(range(1,n+1)))\nprint(v)\n\nans=0\n\nfor x in v:\n tf=True\n if x[0]!=1:\n tf=False\n else:\n for i in range(n-1):\n if not ([x[i],x[i+1]] in g or [x[i+1],x[i]] in g):\n tf=False\n break\n if tf:\n ans+=1\nprint(ans)', 'import itertools\n\nn,m=map(int,input().split())\ng=[list(map(int,input().split())) for _ in range(m)]\nv=list(itertools.permutations(range(1,n+1)))\n\nans=0\n\nfor x in v:\n tf=True\n if x[0]!=1:\n tf=False\n else:\n for i in range(n-1):\n if not ([x[i],x[i+1]] in g or [x[i+1],x[i]] in g):\n tf=False\n break\n if tf:\n ans+=1\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s436727899', 's820140777'] | [11120.0, 8052.0] | [98.0, 70.0] | [404, 395] |
p03805 | u981931040 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['n , m = map(int , input().split())\nedge = [[] for _ in range(m) ]\n#print(edge)\nfor _ in range(m):\n a , b = map(int , input().split())\n a -= 1 ; b -= 1\n edge[a].append(b)\n edge[b].append(a)\nprint(edge)\n\ndef DFS(s):\n global visited\n #ret=1 if all(visited) else 0\n if all(visited):\n ret = 1\n else:\n ret = 0\n for e in edge[s]:\n print("e",e)\n if visited[e] == True:\n continue\n visited[e] = True\n ret += DFS(e)\n visited[e] = False\n return ret\n\nvisited = [False] * n\nvisited[0] = True\nprint(DFS[0])', 'n , m = map(int , input().split())\nedge = [[] for _ in range(m) ]\n#print(edge)\nfor _ in range(m):\n a , b = map(int , input().split())\n a -= 1 ; b -= 1\n edge[a].append(b)\n edge[b].append(a)\n#print(edge)\n\ndef DFS(s):\n global visited\n #ret=1 if all(visited) else 0\n if all(visited):\n ret = 1\n else:\n ret = 0\n for e in edge[s]:\n #print("e",e)\n if visited[e] == True:\n continue\n visited[e] = True\n ret += DFS(e)\n visited[e] = False\n return ret\n\nvisited = [False] * n\nvisited[0] = True\nprint(DFS[0])', 'n , m = map(int , input().split())\nedge = [[] for _ in range(n) ]\n#print(edge)\nfor _ in range(m):\n a , b = map(int , input().split())\n a -= 1 ; b -= 1\n edge[a].append(b)\n edge[b].append(a)\n#print(edge)\n\ndef DFS(s):\n global visited\n #ret=1 if all(visited) else 0\n if all(visited):\n ret = 1\n else:\n ret = 0\n for e in edge[s]:\n #print("e",e)\n if visited[e] == True:\n continue\n visited[e] = True\n ret += DFS(e)\n visited[e] = False\n return ret\n\nans = 0\nvisited = [False] * n\nvisited[0] = True\nans += DFS(0)\nprint(ans)\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s118451669', 's813933110', 's314246895'] | [3064.0, 3064.0, 3064.0] | [17.0, 18.0, 28.0] | [581, 583, 603] |
p03805 | u999893056 | 2,000 | 262,144 | You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition | ['import itertools\nimport collections\n\nn, m = map(int, input().split())\n\na = [list(sorted(map(int, input().split()))) for i in range(m)]\na.sort()\n\ncnt = 0\n\nfor i in itertools.permutations(range(2, n + 1), (n - 1)):\n li = [1] + list(i)\n for edge in zip(li, li[1:]):\n print(edge)\n if sum(list(sorted(edge)) in a for edge in zip(li, li[1:])) == n - 1:\n cnt += 1\n\nprint(cnt)\n', 'import itertools\nimport collections\n\nn, m = map(int, input().split())\n\na = [list(sorted(map(int, input().split()))) for i in range(m)]\na.sort()\n\ncnt = 0\n\nfor i in itertools.permutations(range(2, n + 1), (n - 1)):\n li = [1] + list(i)\n if sum(list(sorted(edge)) in a for edge in zip(li, li[1:])) == n - 1:\n cnt += 1\n\nprint(cnt)\n'] | ['Wrong Answer', 'Accepted'] | ['s694053182', 's499473869'] | [3772.0, 3316.0] | [102.0, 61.0] | [391, 339] |
p03806 | u010110540 | 2,000 | 262,144 | Dolphin is planning to generate a small amount of a certain chemical substance C. In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of M_a:M_b. He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy. The pharmacy sells N kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock. The package of chemical i contains a_i grams of the substance A and b_i grams of the substance B, and is sold for c_i yen (the currency of Japan). Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance C. Find the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C by purchasing any combination of packages at the pharmacy, report that fact. | ["def solve():\n \n INF = float('inf')\n \n N, Ma, Mb = map(int, input().split())\n \n l = []\n for _ in range(N):\n a,b,c = map(int, input().split())\n l.append((a,b,c))\n \n #dp table: dp[i][ca][cb] \n dp = [[[INF] * 401 for _ in range(401)] for _ in range(N+1)]\n dp[0][0][0] = 0\n \n for i in range(N):\n for ca in range(401):\n for cb in range(401):\n if dp[i][ca][cb] != INF:\n dp[i+1][ca][cb] = min(dp[i][ca][cb], dp[i+1][ca][cb]) \n dp[i+1][ca+l[i][0]][cb+l[i][1]] = min(dp[i+1][ca+l[i][0]][cb+l[i][1]], dp[i][ca][cb] + l[i][2]) \n \n ans = INF\n for i in range(N):\n for ca in range(401):\n for cb in range(401):\n if dp[i][ca][cb] != INF:\n if ca * Mb == cb * Ma:\n ans = min(ans, dp[i][ca][cb])\n \n print(-1 if ans == INF else ans)\n\nif __name__ == '__main__':\n solve()", "def solve():\n \n INF = float('inf')\n \n N, Ma, Mb = map(int, input().split())\n \n l = []\n for _ in range(N):\n a,b,c = map(int, input().split())\n l.append((a,b,c))\n \n #dp table: dp[i][ca][cb] \n dp = [[[INF] * 401 for _ in range(401)] for _ in range(N+1)]\n dp[0][0][0] = 0\n \n for i in range(N):\n for ca in range(401):\n for cb in range(401):\n if dp[i][a][b] != INF:\n dp[i+1][a][b] = min(dp[i][a][b], dp[i+1][a][b]) \n dp[i+1][a+l[i][0]][b+l[i][1]] = min(dp[i+1][a+l[i][0]][b+l[i][1]], dp[i][a][b] + l[i][2]) \n \n ans = INF\n for i in range(N):\n for ca in range(401):\n for cb in range(401):\n if dp[i][a][b] != INF:\n if a * Mb == b * Ma:\n ans = min(ans, dp[i][a][b])\n \n print(-1 if ans == INF else ans)\n\nif __name__ == '__main'__:\n solve()", "INF = float('inf')\n\nN, Ma, Mb = map(int, input().split())\n\nl = []\nfor _ in range(N):\n a,b,c = map(int, input().split())\n l.append((a,b,c))\n \n#dp table: dp[i][ca][cb] \ndp = [[[INF] * 401 for _ in range(401)] for _ in range(N+1)]\ndp[0][0][0] = 0\n\nfor i in range(N):\n for ca in range(401):\n for cb in range(401):\n if dp[i][a][b] != INF:\n dp[i+1][a][b] = min(dp[i][a][b], dp[i+1][a][b]) \n dp[i+1][a+l[i][0]][b+l[i][1]] = min(dp[i+1][a+l[i][0]][b+l[i][1]], dp[i][a][b] + l[i][2]) \n \nans = INF\nfor i in range(N):\n for ca in range(401):\n for cb in range(401):\n if dp[i][a][b] != INF:\n if a * Mb == b * Ma:\n ans = min(ans, dp[i][a][b])\n\nprint(-1 if ans == INF else ans)", "INF = float('inf')\n\ndef solve():\n N, Ma, Mb = map(int, input().split())\n l = []\n for _ in range(N):\n a, b, c = map(int, input().split())\n l.append((a, b, c))\n \n dp = [[[INF] * 401 for _ in range(401)] for _ in range(N + 1)]\n dp[0][0][0] = 0\n \n for i in range(N):\n for ca in range(401):\n for cb in range(401):\n if dp[i][ca][cb] != INF:\n dp[i + 1][ca][cb] = min(dp[i + 1][ca][cb], dp[i][ca][cb])\n dp[i + 1][ca + l[i][0]][cb + l[i][1]] = min(dp[i + 1][ca + l[i][0]][cb + l[i][1]], dp[i][ca][cb] + l[i][2])\n \n ans = INF\n for i in range(N+1):\n for ca in range(1, 401):\n for cb in range(1, 401):\n if dp[i][ca][cb] != INF:\n if Ma * cb == Mb * ca:\n ans = min(ans, dp[i][ca][cb])\n \n print(-1 if ans == INF else ans)\n \n \nif __name__ == '__main__':\n solve()"] | ['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s274137086', 's291411882', 's540633730', 's105361541'] | [59428.0, 3064.0, 57844.0, 59504.0] | [1775.0, 17.0, 2107.0, 1892.0] | [1040, 1020, 846, 939] |
p03806 | u074220993 | 2,000 | 262,144 | Dolphin is planning to generate a small amount of a certain chemical substance C. In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of M_a:M_b. He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy. The pharmacy sells N kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock. The package of chemical i contains a_i grams of the substance A and b_i grams of the substance B, and is sold for c_i yen (the currency of Japan). Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance C. Find the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C by purchasing any combination of packages at the pharmacy, report that fact. | ['N, Ma, Mb = map(int, input().split())\nMed = [tuple(map(int, input().split())) for _ in range(N)]\nN *= 100\nimport numpy as np\ndp = np.full((N+1,N+1),np.inf) \ndp[0,0] = 0\nfrom itertools import product\nR = lambda x:reversed(range(x,N+1))\nfor a,b,c in Med:\n for i,j in product(R(a),R(b)):\n dp[i,j] = min(dp[i,j], dp[i-a,j-b]+c)\n \nans = np.inf\nfor n in range(1,min(N//Ma, N//Mb)):\n ans = min(ans, dp[n*Ma, n*Mb])\nprint(ans if ans != np.inf else -1)', 'import math\nnmax = 40\nabmax = 10\nINF = 10000\n\n\nN, Ma, Mb = map(int, input().split())\nmedichine = []\nfor i in range(N):\n Lst = [int(x) for x in input().split()]\n medichine.append(Lst)\n\ndp = {}\n\nfor i in range(N+1):\n for ca in range(nmax*abmax+1):\n for cb in range(nmax*abmax+1):\n dp[i,ca,cb] = INF\ndp[0,0,0] = 0\n\nfor i in range(N):\n for ca in range(nmax*abmax+1):\n for cb in range(nmax*abmax+1):\n if dp[i,ca,cb] != INF:\n dp[i+1,ca,cb] = min(dp[i+1,ca,cb],dp[i,ca,cb])\n dp[i+1,ca+medichine[i][0],cb+medichine[i][1]] = min(dp[i+1,ca+medichine[i][0],cb+medichine[i][1]], dp[i,ca,cb]+medichine[i][2])\n\nans = INF\nfor ca in range(nmax*abmax+1):\n for cb in range(nmax*abmax+1):\n if ca*Mb == cb*Ma:\n ans = min(ans,dp[N,ca,cb])\n\nif ans == INF:\n ans = -1\nprint(ans)', '\nINF = 5000\n\ndef dp(n, medichine, Ma, Mb):\n INF = 5000\n if n == 0: \n List = [[0, 0, 0], medichine[n]]\n if medichine[n][0] * Mb == medichine[n][1] * Ma:\n cost = medichine[n][2]\n else:\n cost = INF\n else: \n previous = dp(n-1, medichine, Ma, Mb)\n List = previous[0].copy()\n cost = previous[1]\n if medichine[n][2] > cost:\n for x in previous[0]:\n C = x[2] + medichine[n][2]\n if C > cost:\n continue\n A = x[0] + medichine[n][0]\n B = x[1] + medichine[n][1]\n List.append([A, B, C])\n if A * Mb == B * Ma:\n cost = C \n return List, cost\n\n\n\nN, Ma, Mb = map(int, input().split())\nmedichine = []\nfor i in range(N):\n Lst = [int(x) for x in input().split()]\n medichine.append(Lst)\nans = dp(N-1, medichine, Ma, Mb)\ncost = ans[1]\nif cost != INF:\n print(cost)\nelse:\n print(-1)', 'import math\nnmax = 40\nabmax = 10\nINF = 10000\n\n\nN, Ma, Mb = map(int, input().split())\nmedichine = []\nfor i in range(N):\n Lst = [int(x) for x in input().split()]\n medichine.append(Lst)\n\ndp = {}\n\nfor i in range(N+1):\n for ca in range(nmax*abmax+1):\n for cb in range(nmax*abmax+1):\n dp[i,ca,cb] = INF\ndp[0,0,0] = 0\n\nfor i in range(N):\n for ca in range(nmax*abmax+1):\n for cb in range(nmax*abmax+1):\n if dp[i,ca,cb] != INF:\n dp[i+1,ca,cb] = min(dp[i+1,ca,cb],dp[i,ca,cb])\n dp[i+1,ca+medichine[i][0],cb+medichine[i][1]] = min(dp[i+1,ca+medichine[i][0],cb+medichine[i][1]], dp[i,ca,cb]+medichine[i][2])\n\nans = INF\nfor ca in range(nmax*abmax+1):\n for cb in range(nmax*abmax+1):\n if ca*Mb == cb*Ma:\n ans = min(ans,dp[N,ca,cb])\n\nif ans == INF:\n ans = -1\nprint(ans)', 'N, Ma, Mb = map(int, input().split())\nMed = [tuple(map(int, input().split())) for _ in range(N)]\nINF = 100000\nfrom collections import defaultdict as dd\ndp = [dd(lambda:INF) for _ in range(N+1)]\nfor n in range(1,N+1):\n a,b,c = Med[n-1]\n dp[n-1][0,0] = 0\n for (i,j),value in dp[n-1].items():\n dp[n][i+a,j+b] = min(dp[n-1][i+a,j+b],value+c)\n\nans = INF\nfor (i,j),value in dp[N].items():\n if i == j == 0:\n continue\n if i*Mb == j*Ma:\n ans = min(ans, value)\nprint(ans if ans != INF else -1)', 'N, Ma, Mb = map(int, input().split())\nMed = [tuple(map(int, input().split())) for _ in range(N)]\nN *= 100\nINF = 100000\ndp = [[INF]*N+1 for _ in range(N+1)] \ndp[0][0] = 0 \nfrom itertools import product as prd\nR = lambda x:reversed(range(x,N+1))\nfor a,b,c in Med:\n for i,j in prd(R(a),R(b)):\n dp[i][j] = min(dp[i][j], dp[i-a][j-b]+c)\n\nans = INF\nfor i,j in prd(R(1),R(1)):\n if i*Mb == j*Ma:\n ans = min(ans, dp[i][j])\nprint(ans if ans != INF else -1)', 'import collections\nimport copy\nINF = 10000\n\n\nN, Ma, Mb = map(int, input().split())\nmedichine = [tuple(map(int, input().split())) for _ in range(N)]\n\ndp = {}\n\ndp = collections.defaultdict(lambda:INF)\ndp[0,0] = 0\n\nfor a, b, c in medichine:\n dp_ = copy.copy(dp)\n for ca,cb in dp.keys():\n dp_[ca+a, cb+b] = min(dp_[ca+a, cb+b], dp[ca,cb]+c)\n dp = dp_ \n\nans = INF\nfor ca,cb in dp.keys():\n if ca == cb == 0: continue\n if ca*Mb == cb*Ma:\n ans = min(ans, dp[ca,cb])\n \nprint(-1 if ans == INF else ans)'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s084313856', 's093206971', 's272785038', 's608808775', 's641199614', 's704777884', 's301861222'] | [152180.0, 719968.0, 9228.0, 590648.0, 9480.0, 9236.0, 12640.0] | [2206.0, 2222.0, 31.0, 2221.0, 25.0, 26.0, 221.0] | [524, 887, 1059, 887, 581, 527, 550] |
p03806 | u116002573 | 2,000 | 262,144 | Dolphin is planning to generate a small amount of a certain chemical substance C. In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of M_a:M_b. He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy. The pharmacy sells N kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock. The package of chemical i contains a_i grams of the substance A and b_i grams of the substance B, and is sold for c_i yen (the currency of Japan). Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance C. Find the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C by purchasing any combination of packages at the pharmacy, report that fact. | ["def main():\n\n N, Ma, Mb = map(int, input().split())\n drug = []\n for _ in range(N):\n a, b, c = map(int, input().split())\n drug.append([a, b, c])\n\n cur = dict()\n cur[(0, 0)] = 0\n for i in range(N):\n temp = cur.copy()\n for p in cur:\n a, b = p[0]+drug[i][0], p[1]+drug[i][1]\n\n if (a, b) not in temp:\n temp[(a, b)] = cur[p] + drug[i][2]\n else:\n temp[(a, b)] = min(temp[(a, b)], cur[p]+drug[i][2])\n cur = temp\n\n # print(cur)\n min_c = float('inf')\n for p in cur:\n if p != (0, 0) and p[0]*Mb == p[1]*Ma:\n min_c = min(min_c, cur[p])\n if min_c == float('inf'):\n return -1\n else:\n return min_c\n", "def main():\n\n N, Ma, Mb = map(int, input().split())\n drug = []\n for _ in range(N):\n a, b, c = map(int, input().split())\n drug.append([a, b, c])\n\n cur = dict()\n cur[(0, 0)] = 0\n for i in range(N):\n temp = cur.copy()\n for p in cur:\n a, b = p[0]+drug[i][0], p[1]+drug[i][1]\n\n if (a, b) not in temp:\n temp[(a, b)] = cur[p] + drug[i][2]\n else:\n temp[(a, b)] = min(temp[(a, b)], cur[p]+drug[i][2])\n cur = temp\n\n # print(cur)\n min_c = float('inf')\n for p in cur:\n if p != (0, 0) and p[0]*Mb == p[1]*Ma:\n min_c = min(min_c, cur[p])\n if min_c == float('inf'):\n return -1\n else:\n return min_c\n\nif __name__ == '__main__':\n print(main())"] | ['Wrong Answer', 'Accepted'] | ['s112986635', 's714759393'] | [3064.0, 8332.0] | [17.0, 253.0] | [746, 791] |
p03806 | u119226758 | 2,000 | 262,144 | Dolphin is planning to generate a small amount of a certain chemical substance C. In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of M_a:M_b. He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy. The pharmacy sells N kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock. The package of chemical i contains a_i grams of the substance A and b_i grams of the substance B, and is sold for c_i yen (the currency of Japan). Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance C. Find the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C by purchasing any combination of packages at the pharmacy, report that fact. | ['import math\n\nN, Ma, Mb = map(int,input().split())\nrate = Ma / Mb\na = [0] * N\nb = [0] * N\nc = [0] * N\nMA = 0\nMB = 0\nfor i in range(N):\n a[i], b[i], c[i] = map(int, input().split())\n MA += a[i]\n MB += b[i]\n\ndp = [[[math.inf for i in range(MB+1)] for j in range(MA+1)] for k in range(N+1)]\ndp[0][0][0] = 0\n\nfor it_N in range(N):\n for it_MA in range(MA+1):\n for it_MB in range(MB+1):\n if it_MA >= a[it_N] and it_MB >= b[it_N]:\n if dp[it_N][it_MA-a[it_N]][it_MB-b[it_N]] != math.inf:\n dp[it_N+1][it_MA][it_MB] = min(dp[it_N][it_MA-a[it_N]][it_MB-b[it_N]] + c[it_N], dp[it_N][it_MA][it_MB])\n else:\n dp[it_N+1][it_MA][it_MB]=dp[it_N][it_MA][it_MB]\n\n for it_MA in range(MA+1):\n for it_MB in range(MB+1):\n# print(it_N+1,it_MA,it_MB,dp[it_N+1][it_MA][it_MB])\n\n\nans = -1\nfor a in range(1, MA+1):\n for b in range(1, MB+1):\n print(a,b,dp[N][a][b])\n if a/b == rate and dp[N][a][b] != math.inf:\n if ans == -1:\n ans = dp[N][a][b]\n else:\n ans = min([dp[N][a][b], ans])\nprint(ans)\n', 'import math\n\nN, Ma, Mb = map(int,input().split())\nrate = Ma / Mb\na = [0] * N\nb = [0] * N\nc = [0] * N\nMA = 0\nMB = 0\nfor i in range(N):\n a[i], b[i], c[i] = map(int, input().split())\n MA += a[i]\n MB += b[i]\n\ndp = [[[math.inf for i in range(MB+1)] for j in range(MA+1)] for k in range(N+1)]\ndp[0][0][0] = 0\n\nfor it_N in range(N):\n for it_MA in range(MA+1):\n for it_MB in range(MB+1):\n if it_MA >= a[it_N] and it_MB >= b[it_N]:\n if dp[it_N][it_MA-a[it_N]][it_MB-b[it_N]] != math.inf:\n dp[it_N+1][it_MA][it_MB] = min(dp[it_N][it_MA-a[it_N]][it_MB-b[it_N]] + c[it_N], dp[it_N][it_MA][it_MB])\n else:\n dp[it_N+1][it_MA][it_MB]=dp[it_N][it_MA][it_MB]\n\n for it_MA in range(MA+1):\n for it_MB in range(MB+1):\n print(it_N+1,it_MA,it_MB,dp[it_N+1][it_MA][it_MB])\n\n\nans = -1\nfor a in range(1, MA+1):\n for b in range(1, MB+1):\n print(a,b,dp[N][a][b])\n if a/b == rate and dp[N][a][b] != math.inf:\n if ans == -1:\n ans = dp[N][a][b]\n else:\n ans = min([dp[N][a][b], ans])\nprint(ans)\n', 'import math\n\nN, Ma, Mb = map(int,input().split())\nrate = Ma / Mb\na = [0] * N\nb = [0] * N\nc = [0] * N\nMA = 0\nMB = 0\nfor i in range(N):\n a[i], b[i], c[i] = map(int, input().split())\n MA += a[i]\n MB += b[i]\n\ndp = [[[math.inf for i in range(MB+1)] for j in range(MA+1)] for k in range(N+1)]\ndp[0][0][0] = 0\n\nfor it_N in range(N):\n for it_MA in range(MA+1):\n for it_MB in range(MB+1):\n if it_MA >= a[it_N] and it_MB >= b[it_N]:\n if dp[it_N][it_MA-a[it_N]][it_MB-b[it_N]] != math.inf:\n dp[it_N+1][it_MA][it_MB] = min(dp[it_N][it_MA-a[it_N]][it_MB-b[it_N]] + c[it_N], dp[it_N][it_MA][it_MB])\n else:\n dp[it_N+1][it_MA][it_MB]=dp[it_N][it_MA][it_MB]\n\nans = -1\nfor a in range(1, MA+1):\n for b in range(1, MB+1):\n print(a,b,dp[N][a][b])\n if a/b == rate and dp[N][a][b] != math.inf:\n if ans == -1:\n ans = dp[N][a][b]\n else:\n ans = min([dp[N][a][b], ans])\nprint(ans)\n', '\nN, Ma, Mb = map(int,input().split())\nrate = Ma / Mb\na = [0] * N\nb = [0] * N\nc = [0] * N\nMA = 0\nMB = 0\nfor i in range(N):\n a[i], b[i], c[i] = map(int, input().split())\n MA += a[i]\n MB += b[i]\n\ndp = [[[0 for i in range(MB+1)] for j in range(MA+1)] for k in range(N+1)]\n\nfor it_N in range(N):\n for it_MA in range(MA+1):\n for it_MB in range(MB+1):\n if it_MA > a[it_N] and it_MB > b[it_N]:\n if dp[it_N][it_MA-a[it_N]][it_MB-b[it_N]] != 0:\n dp[it_N+1][it_MA][it_MB] = min(dp[it_N][it_MA-a[it_N]][it_MB-b[it_N]] + c[it_N], dp[it_N][it_MA][it_MB])\n else:\n dp[it_N+1][a[it_N]][b[it_N]] = c[it_N]\n\n\nans = -1\nfor a in range(1, MA+1):\n for b in range(1, MB+1):\n if a/b == rate and dp[N][a][b] != 0:\n if ans == -1:\n ans = dp[N][a][b]\n else:\n ans = min([dp[N][a][b], ans])\nprint(ans)\n', '\nN, Ma, Mb = map(int,input().split())\nrate = Ma / Mb\na = [0] * N\nb = [0] * N\nc = [0] * N\nMA = 0\nMB = 0\nMC = 0\nfor i in range(N):\n a[i], b[i], c[i] = map(int, input().split())\n MA += a[i]\n MB += b[i]\n MC += c[i]\n \ndp = [[[MC for i in range(MB+1)] for j in range(MA+1)] for k in range(N+1)]\ndp[0][0][0] = 0\n\nfor it_N in range(N):\n for it_MA in range(MA+1):\n for it_MB in range(MB+1):\n if it_MA >= a[it_N] and it_MB >= b[it_N]:\n if dp[it_N][it_MA-a[it_N]][it_MB-b[it_N]] != MC:\n dp[it_N+1][it_MA][it_MB] = min(dp[it_N][it_MA-a[it_N]][it_MB-b[it_N]] + c[it_N], dp[it_N][it_MA][it_MB])\n else:\n dp[it_N+1][it_MA][it_MB]=dp[it_N][it_MA][it_MB]\n else:\n dp[it_N+1][it_MA][it_MB]=dp[it_N][it_MA][it_MB]\n\nans = -1\nfor a in range(1, MA+1):\n for b in range(1, MB+1):\n if a/b == rate and dp[N][a][b] != MC:\n if ans == -1:\n ans = dp[N][a][b]\n else:\n ans = min(dp[N][a][b], ans)\nprint(ans)\n'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s074730363', 's105563733', 's197478403', 's337982297', 's717474414'] | [3064.0, 3188.0, 3184.0, 23156.0, 26216.0] | [18.0, 18.0, 18.0, 1580.0, 1717.0] | [1156, 1155, 1013, 944, 1066] |
p03806 | u190405389 | 2,000 | 262,144 | Dolphin is planning to generate a small amount of a certain chemical substance C. In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of M_a:M_b. He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy. The pharmacy sells N kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock. The package of chemical i contains a_i grams of the substance A and b_i grams of the substance B, and is sold for c_i yen (the currency of Japan). Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance C. Find the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C by purchasing any combination of packages at the pharmacy, report that fact. | ["n,ma,mb = map(int, input().split())\nabc = [list(map(int, input().split())) for i in range(n)]\n\ninf = float('inf')\n\ndp = [[inf for i in range(n*10)] for i in range(n*10)]\n\nfor i in range(n):\n for j in range(i*10,-1):\n for k in range(i*10,-1):\n if dp[j][k]!=inf:\n dp[j + abc[i][0]][k + abc[i][1]] =min(dp[j+abc[i][0]][k+abc[i][1]],dp[j][k]+abc[i][2])\n dp[abc[i][0] - 1][abc[i][1] - 1]= min(dp[abc[i][0] - 1][abc[i][1] - 1], abc[i][2])\n\nans = inf\n\nfor j in range(n*10):\n for k in range(n*10):\n if ma*(k+1)==mb*(j+1):\n ans = min(ans,dp[j][k])\n\nprint(ans if ans!=inf else -1)\n", "n,ma,mb = map(int, input().split())\nabc = [list(map(int, input().split())) for i in range(n)]\n\ninf = float('inf')\n\ndp = [[inf for i in range(n*10)] for i in range(n*10)]\n\nfor i in range(n):\n for j in range(i*10-1,-1,-1):\n for k in range(i*10-1,-1,-1):\n if dp[j][k]!=inf:\n dp[j + abc[i][0]][k + abc[i][1]] =min(dp[j+abc[i][0]][k+abc[i][1]],dp[j][k]+abc[i][2])\n dp[abc[i][0] - 1][abc[i][1] - 1]= min(dp[abc[i][0] - 1][abc[i][1] - 1], abc[i][2])\n\nans = inf\n\nfor j in range(n*10):\n for k in range(n*10):\n if ma*(k+1)==mb*(j+1):\n ans = min(ans,dp[j][k])\n\nprint(ans if ans!=inf else -1)"] | ['Wrong Answer', 'Accepted'] | ['s154908085', 's526947617'] | [4340.0, 4852.0] | [58.0, 533.0] | [631, 640] |
p03806 | u210440747 | 2,000 | 262,144 | Dolphin is planning to generate a small amount of a certain chemical substance C. In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of M_a:M_b. He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy. The pharmacy sells N kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock. The package of chemical i contains a_i grams of the substance A and b_i grams of the substance B, and is sold for c_i yen (the currency of Japan). Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance C. Find the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C by purchasing any combination of packages at the pharmacy, report that fact. | ['import numpy as np\n\nif __name__=="__main__":\n inputs_number = lambda : [int(x) for x in input().split()]\n N, Ma, Mb = inputs_number()\n drugs = np.array([inputs_number() for i in range(N)])\n\n inf = 100*N + 1\n dp = np.ones((N,N*10,N*10)) * inf\n dp[0,0,0] = 0\n for i in range(0, N-1):\n\tfor ca in range(N*10):\n for cb in range(N*10):\n\t\tif(dp[i,ca,cb]==inf):\n continue\n\t\tdp[i+1,ca,cb]=np.min([dp[i+1,ca,cb],dp[i,ca,cb]]);\n\t\tdp[i+1,ca+drugs[i,0],cb+drugs[i,1]]=np.min([dp[i+1,ca+drugs[i,0],cb+drugs[i,1]],dp[i,ca,cb]+drugs[i,2]]);\n\n ans = inf\n for i in range(1, N):\n\tfor ca in range(1, N*10):\n for cb in range(1, N*10):\n\t\tif(Ma*cb == Mb*ca and dp[i,ca,cb] < ans):\n ans = dp[i,ca,cb]\n if(ans==inf):\n\tans = -1\n print(int(ans))', 'import numpy as np\n\nif __name__=="__main__":\n inputs_number = lambda : [int(x) for x in input().split()]\n N, Ma, Mb = inputs_number()\n drugs = np.array([inputs_number() for i in range(N)]).astype(np.int16)\n\n inf = 100*N + 1\n dp = np.ones((N+1,N*10+1,N*10+1)) * inf\n dp[0,0,0] = 0\n for i in range(N):\n\tfor ca in range(N*10+1):\n for cb in range(N*10+1):\n\t\tif(dp[i,ca,cb]==inf):\n continue\n\t\tdp[i+1,ca,cb]=np.min([dp[i+1,ca,cb],dp[i,ca,cb]]);\n\t\tdp[i+1,ca+drugs[i,0],cb+drugs[i,1]]=np.min([dp[i+1,ca+drugs[i,0],cb+drugs[i,1]],dp[i,ca,cb]+drugs[i,2]]);\n\n ans = inf\n for ca in range(1, N*10+1):\n for cb in range(1, N*10+1):\n\t if(Ma*cb == Mb*ca and dp[N,ca,cb] < ans):\n \tans = dp[N,ca,cb]\n if(ans==inf):\n\tans = -1\n print(int(ans))', 'import numpy as np\n\nif __name__=="__main__":\n inputs_number = lambda : [int(x) for x in input().split()]\n N, Ma, Mb = inputs_number()\n drugs = [inputs_number() for i in range(N)]\n inf = 100*N + 1\n dp = np.ones((N+1,N*10+1,N*10+1)).astype(np.int32) * inf\n dp = dp.tolist()\n dp[0][0][0] = 0.0\n\n for i in range(N):\n\tfor ca in range(N*i+1):\n for cb in range(N*i+1):\n if(dp[i][ca][cb]==inf):\n continue\n dp[i+1][ca][cb]=min([dp[i+1][ca][cb], dp[i][ca][cb]])\n dp[i+1][ca+drugs[i][0]][cb+drugs[i][1]]=min([dp[i+1][ca+drugs[i][0]][cb+drugs[i][1]], dp[i][ca][cb]+drugs[i][2]])\n ans = inf\n for ca in range(1, N*10+1):\n for cb in range(1, N*10+1):\n if(Ma*cb==Mb*ca and dp[N][ca][cb]<ans):\n ans = dp[N][ca][cb]\n if(ans==inf):\n ans = -1\n print(int(ans))', 'import numpy as np\n\nif __name__=="__main__":\n inputs_number = lambda : [int(x) for x in input().split()]\n N, Ma, Mb = inputs_number()\n drugs = np.array([inputs_number() for i in range(N)])\n\n inf = 100*N + 1\n dp = np.ones((N+1,N*10+1,N*10+1)) * inf\n dp[0,0,0] = 0\n for i in range(0, N):\n\tfor ca in range(N*10+1):\n for cb in range(N*10+1):\n\t\tif(dp[i,ca,cb]==inf):\n continue\n\t\tdp[i+1,ca,cb]=np.min([dp[i+1,ca,cb],dp[i,ca,cb]]);\n\t\tdp[i+1,ca+drugs[i,0],cb+drugs[i,1]]=np.min([dp[i+1,ca+drugs[i,0],cb+drugs[i,1]],dp[i,ca,cb]+drugs[i,2]]);\n\n ans = inf\n for ca in range(1, N*10+1):\n for cb in range(1, N*10+1):\n\t if(Ma*cb == Mb*ca and dp[i,ca,cb] < ans):\n \tans = dp[i,ca,cb]\n if(ans==inf):\n\tans = -1\n print(int(ans))', 'import numpy as np\n\nif __name__=="__main__":\n inputs_number = lambda : [int(x) for x in input().split()]\n N, Ma, Mb = inputs_number()\n drugs = [inputs_number() for i in range(N)]\n\n inf = 100*N + 1\n dp = np.ones((N+1,N*10+1,N*10+1)) * inf\n dp[0,0,0] = 0\n for i in range(N):\n\tfor ca in range(N*10+1):\n for cb in range(N*10+1):\n\t\tif(dp[i,ca,cb]==inf):\n continue\n dp[i+1,ca,cb]=np.min([dp[i+1,ca,cb],dp[i,ca,cb]])\n dp[i+1,ca+drugs[i][0],cb+drugs[i][1]]=np.min([dp[i+1,ca+drugs[i][0],cb+drugs[i][1]],dp[i,ca,cb]+drugs[i][2]])\n\n ans = inf\n for ca in range(1, N*10+1):\n for cb in range(1, N*10+1):\n\t if(Ma*cb==Mb*ca and dp[N,ca,cb]<ans):\n \tans = dp[N,ca,cb]\n if(ans==inf):\n\tans = -1\n print(int(ans))', 'import numpy as np\n\nif __name__=="__main__":\n inputs_number = lambda : [int(x) for x in input().split(" ")]\n N, Ma, Mb = inputs_number()\n drugs = np.array([inputs_number() for i in range(N)])\n\n inf = 100*N + 1\n dp = np.ones((N,N*10,N*10)) * inf\n dp[0,0,0] = 0\n for i in range(0, N-1):\n\tfor ca in range(N*10):\n for cb in range(N*10):\n\t\tif(dp[i,ca,cb]==inf):\n continue\n\t\tdp[i+1,ca,cb]=np.min([dp[i+1,ca,cb],dp[i,ca,cb]]);\n\t\tdp[i+1,ca+drugs[i,0],cb+drugs[i,1]]=np.min([dp[i+1,ca+drugs[i,0],cb+drugs[i,1]],dp[i,ca,cb]+drugs[i,2]]);\n\n ans = inf\n for i in range(1, N):\n\tfor ca in range(1, N*10):\n for cb in range(1, N*10):\n\t\tif(Ma*cb == Mb*ca and dp[i,ca,cb] < ans):\n ans = dp[i,ca,cb]\n if(ans==inf):\n\tans = -1\n print(int(ans))', 'import numpy as np\n\nif __name__=="__main__":\n inputs_number = lambda : [int(x) for x in input().split()]\n N, Ma, Mb = inputs_number()\n drugs = [inputs_number() for i in range(N)]\n inf = 100*N + 1\n dp = np.ones((N+1,N*10+1,N*10+1)).astype(np.int32) * inf\n dp = dp.tolist()\n dp[0][0][0] = 0.0\n\n for i in range(N):\n for ca in range(N*(i+1)+1):\n for cb in range(N*(i+1)+1):\n if(dp[i][ca][cb]==inf):\n continue\n dp[i+1][ca][cb]=min([dp[i+1][ca][cb], dp[i][ca][cb]])\n dp[i+1][ca+drugs[i][0]][cb+drugs[i][1]]=min([dp[i+1][ca+drugs[i][0]][c\\\nb+drugs[i][1]], dp[i][ca][cb]+drugs[i][2]])\n ans = inf\n for ca in range(1, N*10+1):\n for cb in range(1, N*10+1):\n if(Ma*cb==Mb*ca and dp[N][ca][cb]<ans):\n ans = dp[N][ca][cb]\n if(ans==inf):\n ans = -1\n print(int(ans))', 'import numpy as np\nimport copy\n\nif __name__=="__main__":\n inputs_number = lambda : [int(x) for x in input().split()]\n N, Ma, Mb = inputs_number()\n drugs = [inputs_number() for i in range(N)]\n inf = 100*N + 1\n dp = np.ones((2,N*10+1,N*10+1)).astype(np.int32) * inf\n dp = dp.tolist()\n dp[0][0][0] = 0.0\n\n for i in range(N):\n for ca in range(10*i+1):\n for cb in range(10*i+1):\n if(dp[0][ca][cb]==inf):\n continue\n dp[1][ca][cb]=min([dp[1][ca][cb], dp[0][ca][cb]])\n dp[1][ca+drugs[i][0]][cb+drugs[i][1]]=min([dp[1][ca+drugs[i][0]][cb+drugs[i][1]], dp[0][ca][cb]+drugs[i][2]])\n dp[0] = copy.copy(dp[1])\n dp[1] = (np.ones((N*10+1,N*10+1)).astype(np.int32) * inf).tolist()\n print(np.array(dp).shape)\n ans = inf\n for ca in range(1, N*10+1):\n for cb in range(1, N*10+1):\n if(Ma*cb==Mb*ca and dp[0][ca][cb]<ans):\n ans = dp[0][ca][cb]\n if(ans==inf):\n ans = -1\n print(int(ans))', 'import numpy as np\n\nif __name__=="__main__":\n inputs_number = lambda : [int(x) for x in input().replace("\\n", "").split(" ")]\n N, Ma, Mb = inputs_number()\n drugs = np.array([inputs_number() for i in range(N)])\n\n inf = 100*N + 1\n dp = np.ones((N,N*10,N*10)) * inf\n dp[0,0,0] = 0\n for i in range(0, N-1):\n for ca in range(N*10):\n for cb in range(N*10):\n if(dp[i,ca,cb]==inf):\n continue\n dp[i+1,ca,cb]=np.min([dp[i+1,ca,cb],dp[i,ca,cb]]);\n dp[i+1,ca+drugs[i,0],cb+drugs[i,1]]=np.min([dp[i+1,ca+drugs[i,0],cb+drugs[i,1]],dp[i,ca,cb]+drugs[i,2]]);\n\n ans = inf\n for i in range(1, N):\n for ca in range(1, N*10):\n for cb in range(1, N*10):\n if(Ma*cb == Mb*ca and dp[i,ca,cb] < ans):\n ans = dp[i,ca,cb]\n if(ans == inf):\n\tans = -1\n print(int(ans))\n', 'import numpy as np\n\nif __name__=="__main__":\n inputs_number = lambda : [int(x) for x in input().split()]\n N, Ma, Mb = inputs_number()\n drugs = [inputs_number() for i in range(N)]\n inf = 100*N + 1\n dp = np.ones((N+1,N*10+1,N*10+1)).astype(np.int32) * inf\n dp = dp.tolist()\n print(type(dp[0][0][0]))\n dp[0][0][0] = 0.0\n\n for i in range(N):\n for ca in range(N*10+1):\n for cb in range(N*10+1):\n if(dp[i][ca][cb]==inf):\n continue\n dp[i+1][ca][cb]=min([dp[i+1][ca][cb], dp[i][ca][cb]])\n dp[i+1][ca+drugs[i][0]][cb+drugs[i][1]]=min([dp[i+1][ca+drugs[i][0]][cb+drugs[i][1]], dp[i][ca][cb]+drugs[i][2]])\n ans = inf\n for ca in range(1, N*10+1):\n for cb in range(1, N*10+1):\n if(Ma*cb==Mb*ca and dp[N][ca][cb]<ans):\n ans = dp[N][ca][cb]\n if(ans==inf):\n ans = -1\n print(int(ans))', 'import numpy as np\n\nif __name__=="__main__":\n inputs_number = lambda : [int(x) for x in input().split()]\n N, Ma, Mb = inputs_number()\n drugs = [inputs_number() for i in range(N)]\n\n inf = 100*N + 1\n dp = np.ones((N+1,N*10+1,N*10+1)) * inf\n dp[0,0,0] = 0\n for i in range(N):\n\tfor ca in range(N*10+1):\n for cb in range(N*10+1):\n\t\tif(dp[i,ca,cb]==inf):\n continue\n\t\tdp[i+1,ca,cb]=np.min([dp[i+1,ca,cb],dp[i,ca,cb]]);\n\t\tdp[i+1,ca+drugs[i][0],cb+drugs[i][1]]=np.min([dp[i+1,ca+drugs[i][0],cb+drugs[i][1]],dp[i,ca,cb]+drugs[i][2]]);\n\n ans = inf\n for ca in range(1, N*10+1):\n for cb in range(1, N*10+1):\n\t if(Ma*cb == Mb*ca and dp[N,ca,cb] < ans):\n \tans = dp[N,ca,cb]\n if(ans==inf):\n\tans = -1\n print(int(ans))\n', 'import numpy as np\n\nif __name__=="__main__":\n inputs_number = lambda : [int(x) for x in input().split()]\n N, Ma, Mb = inputs_number()\n drugs = [inputs_number() for i in range(N)]\n inf = 100*N + 1\n dp = np.ones((N+1,N*10+1,N*10+1)) * inf\n dp[0,0,0] = 0.0\n for i in range(N):\n\tfor ca in range(N*10+1):\n for cb in range(N*10+1):\n\t\tif(dp[i,ca,cb]==inf):\n continue\n dp[i+1,ca,cb]=np.min([dp[i+1,ca,cb],dp[i,ca,cb]])\n dp[i+1,ca+drugs[i][0],cb+drugs[i][1]]=np.min([dp[i+1,ca+drugs[i][0],cb+drugs[i][1]],dp[i,ca,cb]+drugs[i][2]])\n print(-1)\n ans = inf\n for ca in range(1, N*10+1):\n for cb in range(1, N*10+1):\n\t if(Ma*cb==Mb*ca and dp[N,ca,cb]<ans):\n \tans = dp[N,ca,cb]\n if(ans==inf):\n\tans = -1\n #print(int(ans))\n', 'import numpy as np\n\nif __name__=="__main__":\n inputs_number = lambda : [int(x) for x in input().split()]\n N, Ma, Mb = inputs_number()\n drugs = [inputs_number() for i in range(N)]\n inf = 100*N + 1\n dp = np.ones((N+1,N*10+1,N*10+1)) * inf\n dp[0,0,0] = 0.0\n\n for i in range(N):\n\tfor ca in range(N*10+1):\n for cb in range(N*10+1):\n\t\tif(dp[i,ca,cb]==inf):\n continue\n dp[i+1,ca,cb]=np.min([dp[i+1,ca,cb],dp[i,ca,cb]])\n dp[i+1,ca+drugs[i][0],cb+drugs[i][1]]=np.min([dp[i+1,ca+drugs[i][0],cb+drugs[i][1]],dp[i,ca,cb]+drugs[i][2]])', 'import numpy as np\n\nif __name__=="__main__":\n inputs_number = lambda : [int(x) for x in input().split()]\n N, Ma, Mb = inputs_number()\n drugs = np.array([inputs_number() for i in range(N)])\n\n inf = 100*N + 1\n dp = np.ones((N+1,N*10+1,N*10+1)) * inf\n dp[0,0,0] = 0\n for i in range(N):\n\tfor ca in range(N*10+1):\n for cb in range(N*10+1):\n\t\tif(dp[i,ca,cb]==inf):\n continue\n\t\tdp[i+1,ca,cb]=np.min([dp[i+1,ca,cb],dp[i,ca,cb]]);\n\t\tdp[i+1,ca+drugs[i,0],cb+drugs[i,1]]=np.min([dp[i+1,ca+drugs[i,0],cb+drugs[i,1]],dp[i,ca,cb]+drugs[i,2]]);\n\n ans = inf\n for ca in range(1, N*10+1):\n for cb in range(1, N*10+1):\n\t if(Ma*cb == Mb*ca and dp[N,ca,cb] < ans):\n \tans = dp[N,ca,cb]\n if(ans==inf):\n\tans = -1\n print(int(ans))', 'import numpy as np\n\nif __name__=="__main__":\n inputs_number = lambda : [int(x) for x in input().split()]\n N, Ma, Mb = inputs_number()\n drugs = [inputs_number() for i in range(N)]\n inf = 100*N + 1\n dp = np.ones((N+1,N*10+1,N*10+1)) * inf\n dp[0,0,0] = 0.0', 'import numpy as np\n\nif __name__=="__main__":\n inputs_number = lambda : [int(x) for x in input().replace("\\n", "").split(" ")]\n N, Ma, Mb = inputs_number()\n drugs = np.array([inputs_number() for i in range(N)])\n\n inf = 100*N + 1\n dp = np.ones((N,N*10,N*10)) * inf\n dp[0,0,0] = 0\n for i in range(0, N-1):\n for ca in range(N*10):\n for cb in range(N*10):\n if(dp[i,ca,cb]==inf):\n continue\n dp[i+1,ca,cb]=np.min([dp[i+1,ca,cb],dp[i,ca,cb]]);\n dp[i+1,ca+drugs[i,0],cb+drugs[i,1]]=np.min([dp[i+1,ca+drugs[i,0],cb+drugs[i,1]],dp[i,ca,cb]+drugs[i,2]]);\n\n ans = inf\n for i in range(1, N):\n for ca in range(1, N*10):\n for cb in range(1, N*10):\n if(Ma*cb == Mb*ca and dp[i,ca,cb] < ans):\n ans = dp[i,ca,cb]\n if(ans==inf):\n\tans = -1\n print(int(ans))', 'import numpy as np\n\nif __name__=="__main__":\n inputs_number = lambda : [int(x) for x in input().split()]\n N, Ma, Mb = inputs_number()\n drugs = np.array([inputs_number() for i in range(N)])\n print(-1)\n', 'import numpy as np\nimport copy\n\nif __name__=="__main__":\n inputs_number = lambda : [int(x) for x in input().split()]\n N, Ma, Mb = inputs_number()\n drugs = [inputs_number() for i in range(N)]\n inf = 100*N + 1\n dp = np.ones((2,N*10+1,N*10+1)).astype(np.int32) * inf\n dp = dp.tolist()\n dp[0][0][0] = 0.0\n\n for i in range(N):\n for ca in range(10*i+1):\n for cb in range(10*i+1):\n if(dp[0][ca][cb]==inf):\n continue\n dp[1][ca][cb]=min([dp[1][ca][cb], dp[0][ca][cb]])\n dp[1][ca+drugs[i][0]][cb+drugs[i][1]]=min([dp[1][ca+drugs[i][0]][cb+drugs[i][1]], dp[0][ca][cb]+drugs[i][2]])\n dp[0] = copy.copy(dp[1])\n dp[1] = (np.ones((N*10+1,N*10+1)).astype(np.int32) * inf).tolist()\n ans = inf\n for ca in range(1, N*10+1):\n for cb in range(1, N*10+1):\n if(Ma*cb==Mb*ca and dp[0][ca][cb]<ans):\n ans = dp[0][ca][cb]\n if(ans==inf):\n ans = -1\n print(int(ans))'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s020458576', 's050673175', 's085790355', 's124397585', 's156283877', 's171553571', 's260993299', 's357180083', 's497589518', 's716577233', 's725643527', 's732445415', 's771197177', 's832428553', 's872417417', 's884944992', 's987462084', 's064221665'] | [3064.0, 3192.0, 3064.0, 3064.0, 3064.0, 3064.0, 3064.0, 28336.0, 3064.0, 299932.0, 3192.0, 3064.0, 3064.0, 3064.0, 115464.0, 3064.0, 12556.0, 27776.0] | [23.0, 23.0, 23.0, 23.0, 22.0, 22.0, 24.0, 1240.0, 24.0, 2126.0, 22.0, 22.0, 22.0, 22.0, 299.0, 23.0, 162.0, 1233.0] | [812, 807, 891, 793, 807, 815, 908, 1040, 906, 929, 786, 823, 604, 790, 272, 903, 213, 1010] |
p03806 | u263830634 | 2,000 | 262,144 | Dolphin is planning to generate a small amount of a certain chemical substance C. In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of M_a:M_b. He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy. The pharmacy sells N kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock. The package of chemical i contains a_i grams of the substance A and b_i grams of the substance B, and is sold for c_i yen (the currency of Japan). Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance C. Find the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C by purchasing any combination of packages at the pharmacy, report that fact. | ['N, Ma, Mb = map(int, input().split())\n\nINF = 10 ** 8\n\nlst = [[INF] * 401 for i in range(401)]\nlst[0][0] = 0\n\nfor _ in range(N):\n a, b, c = map(int, input().split())\n for i in range(a, 401):\n for j in range(b, 401):\n if lst[i][j] == INF:\n pass\n else:\n lst[i][j] = min(lst[i][j], lst[i - a][j - b] + c)\n\nans = INF\nn = 400 // max(Ma, Mb)\nfor i in range(1, n + 1):\n ans = min(ans, lst[Ma * i][Mb * i])\n\nif ans == INF:\n print (-1)\nelse:\n print (ans)', '\n\nimport numpy as np\n\nN, Ma, Mb = map(int, input().split())\nU = N * 10\n\ndp = np.zeros((U + 1, U + 1), dtype = np.int64)\ntemp = np.zeros_like(dp)\n\nINF = 10 ** 18\ndp += INF\ndp[0, 0] = 0\n\nfor _ in range(N):\n a, b, c = map(int, input().split())\n temp[:] = dp.copy()\n temp[a:, b:] = np.minimum(temp[a:, b:], dp[:-a, :-b] + c)\n dp = temp \n\nanswer = INF\nfor t in range(1, 401):\n a = Ma * t\n b = Mb * t\n if max(a, b) >= U: \n break\n answer = min(answer, dp[a, b])\n\nif answer == INF:\n answer = -1\n\nprint (answer)\n'] | ['Wrong Answer', 'Accepted'] | ['s414435858', 's640792040'] | [4340.0, 18632.0] | [793.0, 264.0] | [518, 641] |
p03806 | u347640436 | 2,000 | 262,144 | Dolphin is planning to generate a small amount of a certain chemical substance C. In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of M_a:M_b. He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy. The pharmacy sells N kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock. The package of chemical i contains a_i grams of the substance A and b_i grams of the substance B, and is sold for c_i yen (the currency of Japan). Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance C. Find the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C by purchasing any combination of packages at the pharmacy, report that fact. | ["INF = float('inf')\nn, ma, mb = map(int, input().split())\ncmax = n * 10\nt = [[INF] * (cmax + 1) for _ in range(cmax + 1)]\nfor _ in range(n):\n a, b, c = map(int, input().split())\n for aa in range(cmax, 0, -1):\n for bb in range(cmax, 0, -1):\n if t[aa][bb] == INF:\n continue\n t[a + aa][b + bb] = min(t[a + aa][b + bb], t[aa][bb] + c)\n t[a][b] = min(t[a][b], c)\nresult = INF\nfor a in range(1, cmax):\n for b in range(1, cmax):\n if a * mb == b * ma:\n t[a][b] = min(t[a][b], result)\nif result == INF:\n result = -1\nprint(result)\n", "import sys\ninf = float('inf')\nn, ma, mb = map(int, input().split())\nt = [[inf] * 401 for _ in range(401)]\nt[0][0] = 0\nfor _ in range(n):\n a, b, c = map(int, input().split())\n for aa in range(400, -1, -1):\n for bb in range(400, -1, -1):\n if t[aa][bb] == inf:\n continue\n if t[a + aa][b + bb] > c + t[aa][bb]:\n t[a + aa][b + bb] = c + t[aa][bb]\nresult = inf\nfor a in range(400, -1, -1):\n for b in range(400, -1, -1):\n if a * mb == b * ma and t[a][b] < result:\n result = t[a][b]\nif result == 0:\n print(-1)\nelse:\n print(result)\n", "import sys\ninf = float('inf')\nn, ma, mb = map(int, input().split())\nt = [[inf] * 401 for _ in range(401)]\nt[0][0] = 0\nfor _ in range(n):\n a, b, c = map(int, input().split())\n for aa in range(400, 0, -1):\n for bb in range(400, 0, -1):\n if t[aa][bb] == inf:\n continue\n if t[a + aa][b + bb] > c + t[aa][bb]:\n t[a + aa][b + bb] = c + t[aa][bb]\nresult = inf\nfor a in range(400, 0, -1):\n for b in range(400, 0, -1):\n if a * mb == b * ma and t[a][b] < result:\n result = t[a][b]\nif result == 0:\n print(-1)\nelse:\n print(result)\n", 'import sys\nn, ma, mb = map(int, input().split())\nt = [[[] for _ in range(100 * n + 1)] for _ in range(n + 1)]\nfor i in range(n):\n a, b, c = map(int, input().split())\n t[i + 1][c].append((a, b))\n for j in range(1, 100 * n + 1):\n for aa, bb in t[i][j]:\n t[i + 1][j].append((aa, bb))\n t[i + 1][c + j].append((a + aa, b + bb))\nfor i in range(1, 100 * n + 1):\n for a, b in t[n][i]:\n if a % ma == 0 and b % mb == 0:\n print(i)\n sys.exit()\nprint(-1)\n', "import sys\ninf = float('inf')\nn, ma, mb = map(int, input().split())\nt = [[inf] * 401 for _ in range(401)]\nt[0][0] = 0\nfor _ in range(n):\n a, b, c = map(int, input().split())\n for aa in range(400, 0, -1):\n for bb in range(400, 0, -1):\n if t[aa][bb] == inf:\n continue\n if t[a + aa][b + bb] > c + t[aa][bb]:\n t[a + aa][b + bb] = c + t[aa][bb]\nresult = inf\nfor a in range(400, 0, -1):\n for b in range(400, 0, -1):\n if a * mb == b * ma and t[a][b] < result:\n result = t[a][b]\nif result == inf:\n print(-1)\nelse:\n print(result)\n", "# DP\nINF = float('inf')\n\nN, Ma, Mb = map(int, input().split())\n\ncmax = N * 10\nt = [[INF] * (cmax + 1) for _ in range(cmax + 1)]\nfor _ in range(N):\n a, b, c = map(int, input().split())\n for aa in range(cmax, 0, -1):\n for bb in range(cmax, 0, -1):\n if t[aa][bb] == INF:\n continue\n t[aa + a][bb + b] = min(t[aa + a][bb + b], t[aa][bb] + c)\n t[a][b] = min(t[a][b], c)\n\nresult = INF\nfor a in range(1, cmax):\n for b in range(1, cmax):\n if a * Mb == b * Ma:\n result = min(result, t[a][b])\nif result == INF:\n result = -1\nprint(result)\n"] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s074672768', 's295008937', 's569011927', 's644642385', 's898568349', 's984055683'] | [4848.0, 4844.0, 4340.0, 478068.0, 4340.0, 4848.0] | [1180.0, 1047.0, 918.0, 2135.0, 1042.0, 1084.0] | [553, 563, 559, 472, 561, 604] |
p03806 | u375616706 | 2,000 | 262,144 | Dolphin is planning to generate a small amount of a certain chemical substance C. In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of M_a:M_b. He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy. The pharmacy sells N kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock. The package of chemical i contains a_i grams of the substance A and b_i grams of the substance B, and is sold for c_i yen (the currency of Japan). Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance C. Find the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C by purchasing any combination of packages at the pharmacy, report that fact. | ['N, Ma, Mb = (list)(map(int, input().split()))\nN_max = 40\nabmax = 10\nl = []\ninf = 10**6\ndp = [[[inf]*401 for _ in range(401)] for _ in range(40)]\n\n\nfor _ in range(N):\n l.append((list)(map(int, input().split())))\n\ndp[0][0][0] = 0\n\nfor i in range(N):\n for ca in range(401):\n for cb in range(401):\n if dp[i][ca][cb] != inf:\n dp[i+1][ca][cb] = min(dp[i+1][ca][cb], dp[i][ca][cb])\n t_a = l[i][0]\n t_b = l[i][1]\n dp[i+1][ca+t_a][cb+t_b] =\\\n min(dp[i+1][ca+t_a][cb+t_b], dp[i][ca][cb]+l[i][2])\n\nans = inf\nfor i in range(401):\n for j in range(401):\n if i*Mb == j*Ma:\n ans = min(ans, dp[N][i][j])\n\nif ans == inf:\n ans = -1\nprint(ans)\n', 'N, Ma, Mb = (list)(map(int, input().split()))\nl = []\ninf = 10**6\ndp = [[[inf]*401 for _ in range(401)] for _ in range(41)]\n\n\nfor _ in range(N):\n l.append((list)(map(int, input().split())))\n\ndp[0][0][0] = 0\n\nfor i in range(N):\n for ca in range(401):\n for cb in range(401):\n if dp[i][ca][cb] != inf:\n dp[i+1][ca][cb] = min(dp[i+1][ca][cb], dp[i][ca][cb])\n t_a = l[i][0]\n t_b = l[i][1]\n dp[i+1][ca+t_a][cb+t_b] =\\\n min(dp[i+1][ca+t_a][cb+t_b], dp[i][ca][cb]+l[i][2])\n\nans = inf\nfor i in range(1, 401):\n for j in range(1, 401):\n if i*Mb == j*Ma:\n ans = min(ans, dp[N][i][j])\n\nif ans == inf:\n ans = -1\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s824751378', 's207231848'] | [59244.0, 59476.0] | [1453.0, 1715.0] | [751, 735] |
p03806 | u393512980 | 2,000 | 262,144 | Dolphin is planning to generate a small amount of a certain chemical substance C. In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of M_a:M_b. He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy. The pharmacy sells N kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock. The package of chemical i contains a_i grams of the substance A and b_i grams of the substance B, and is sold for c_i yen (the currency of Japan). Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance C. Find the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C by purchasing any combination of packages at the pharmacy, report that fact. | ["INF = float('inf')\nN, Ma, Mb = map(int, input().split())\na, b, c = [None] * N, [None] * N, [None] * N\nfor i in range(N):\n a[i], b[i], c[i] = map(int, input().split())\ndp = [[[INF] * (10*N+1) for j in range(10*N+1)] for i in range(N+1)]\ndp[0][0][0] = 0\nfor i in range(N):\n for j in range(10*N+1):\n for k in range(10*N+1):\n if j >= a[i] and k >= b[i]:\n dp[i+1][j][k] = min(dp[i][j][k], dp[i][j-a[i]][k-b[i]]+c[i])\nans = INF\nfor i in range(1, 10*N+1):\n for j in range(1, 10*N+1):\n if i * Mb == j * Ma and ans < dp[N][i][j]:\n ans = dp[N][i][j]\nans = -1 if ans == INF else ans\nprint(ans)", 'from collections import defaultdict\nN, Ma, Mb = map(int, input().split())\nINF, MAX = 1000000000, 10 * N + 1\ndp = defaultdict(lambda : INF)\ndp[(0, 0)] = 0\nfor i in range(N):\n a, b, c = map(int, input().split())\n predp = dp.copy()\n for ab, v in predp.items():\n _a, _b = ab\n dp[(_a+a, _b+b)] = min(dp[(_a+a, _b+b)], v+c)\nans = INF\nfor i in range(1, N+1):\n ans = min(ans, dp[(Ma*i, Mb*i)])\nans = -1 if ans == INF else ans\nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s930558170', 's197712276'] | [57844.0, 10836.0] | [2107.0, 270.0] | [642, 455] |
p03806 | u425351967 | 2,000 | 262,144 | Dolphin is planning to generate a small amount of a certain chemical substance C. In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of M_a:M_b. He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy. The pharmacy sells N kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock. The package of chemical i contains a_i grams of the substance A and b_i grams of the substance B, and is sold for c_i yen (the currency of Japan). Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance C. Find the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C by purchasing any combination of packages at the pharmacy, report that fact. | ['import copy\n\nN, Ma, Mb = [int(n) for n in input().split()]\npd = {(0,0):0}\nfor i in range(N):\n a, b, c = [int(n) for n in input().split()]\n pdcopy = copy.deepcopy(pd)\n for k, v in pdcopy.items():\n nk = (k[0]+a, k[1]+b)\n if nk in pd:\n if pd[nk] > c :\n pd[nk] = c\n else:\n pd[nk] = c\n\nmp = 1000000\nfor i in range(1,401):\n if (Ma*i, Mb*i) in pd:\n mp = min(pd[(Ma*i, Mb*i)], mp)\n\nif mp == 1000000:\n print(-1)\nelse:\n print(mp)\n', 'import copy\n\nN, Ma, Mb = [int(n) for n in input().split()]\npd = {(0,0):0}\nfor i in range(N):\n a, b, c = [int(n) for n in input().split()]\n pdcopy = copy.deepcopy(pd)\n for k, v in pdcopy.items():\n nk = (k[0]+a, k[1]+b)\n if nk in pd:\n if pd[nk] > v + c :\n pd[nk] = v + c\n else:\n pd[nk] = v + c\n\nmp = 1000000\nfor i in range(1,401):\n if (Ma*i, Mb*i) in pd:\n mp = min(pd[(Ma*i, Mb*i)], mp)\n\nif mp == 1000000:\n print(-1)\nelse:\n print(mp)\n'] | ['Wrong Answer', 'Accepted'] | ['s813364412', 's833260285'] | [7884.0, 8844.0] | [1361.0, 1356.0] | [503, 515] |
p03806 | u533885955 | 2,000 | 262,144 | Dolphin is planning to generate a small amount of a certain chemical substance C. In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of M_a:M_b. He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy. The pharmacy sells N kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock. The package of chemical i contains a_i grams of the substance A and b_i grams of the substance B, and is sold for c_i yen (the currency of Japan). Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance C. Find the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C by purchasing any combination of packages at the pharmacy, report that fact. | ['\nNM=40\nABM=10\nMM=400\n\nN,M1,M2=map(int,input().split())\nA=[]\nB=[]\nC=[]\nfor i in range(N):\n a,b,c=map(int,input().split())\n A.append(a)\n B.append(b)\n C.append(c)\ncmax=max(C)\nCM=N*max(C)+1\ndp=[[[CM for broop in range(401)] for aroop in range(401)] for nroop in range(NM+1)]\ndp[0][0][0]=0\nfor i in range(N-1):\n for cb in range(401):\n for ca in range(401):\n if dp[i][ca][cb]==CM:\n continue\n dp[i+1][ca][cb]=min(dp[i+1][ca][cb],dp[i][ca][cb])\n if ca+A[i]<401 and cb+B[i]<401: \n dp[i+1][ca+A[i]][cb+B[i]]=min(dp[i+1][ca+A[i]][cb+B[i]],dp[i][ca][cb]+C[i])\n\nans=CM\nfor cb in range(400):\n CB=cb+1\n for ca in range(400):\n CA=ca+1\n if ca*M2 == cb*M1:\n ans=min(ans,dp[N][CA][CB])\n\nif ans == CM:\n print(-1)\nelse:\n print(ans)', '\nNM=40\nABM=10\nMM=400\n\nN,M1,M2=map(int,input().split())\nA=[]\nB=[]\nC=[]\nfor i in range(N):\n a,b,c=map(int,input().split())\n A.append(a)\n B.append(b)\n C.append(c)\ncmax=max(C)\nCM=N*max(C)+1\ndp=[[[CM for broop in range(401)] for aroop in range(401)] for nroop in range(NM)]\ndp[0][0][0]=0\nfor i in range(N-1):\n for cb in range(401):\n for ca in range(401):\n if dp[i][ca][cb]==CM:\n continue\n dp[i+1][ca][cb]=min(dp[i+1][ca][cb],dp[i][ca][cb])\n if ca+A[i]<401 and cb+B[i]<401: \n dp[i+1][ca+A[i]][cb+B[i]]=min(dp[i+1][ca+A[i]][cb+B[i]],dp[i][ca][cb]+C[i])\n\nans=CM\nfor cb in range(400):\n CB=cb+1\n for ca in range(400):\n CA=ca+1\n if ca*M2 == cb*M1:\n ans=min(ans,dp[N][CA][CB])\n\nif ans == CM:\n print(-1)\nelse:\n print(ans)', '\nNM=40\nABM=10\nMM=400\n\nN,M1,M2=map(int,input().split())\nA=[]\nB=[]\nC=[]\nfor i in range(N):\n a,b,c=map(int,input().split())\n A.append(a)\n B.append(b)\n C.append(c)\ncmax=max(C)\nCM=N*cmax+10\ndp=[[[CM for broop in range(401)] for aroop in range(401)] for nroop in range(N+1)]\ndp[0][0][0]=0\nfor i in range(N):\n for cb in range(401):\n for ca in range(401):\n if dp[i][ca][cb]==CM:\n continue\n dp[i+1][ca][cb]=min(dp[i+1][ca][cb],dp[i][ca][cb])\n if ca+A[i]<401 and cb+B[i]<401:\n dp[i+1][ca+A[i]][cb+B[i]]=min(dp[i+1][ca+A[i]][cb+B[i]],dp[i][ca][cb]+C[i])\n\nans=CM\nfor cb in range(400):\n for ca in range(400):\n CB=cb+1\n CA=ca+1\n if CA*M2 == CB*M1:\n ans=min(ans,dp[N][CA][CB])\n\nif ans == CM:\n print(-1)\nelse:\n print(ans)'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s437141374', 's687826951', 's286166820'] | [59564.0, 59120.0, 60040.0] | [1950.0, 1863.0, 1849.0] | [840, 838, 839] |
p03806 | u550943777 | 2,000 | 262,144 | Dolphin is planning to generate a small amount of a certain chemical substance C. In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of M_a:M_b. He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy. The pharmacy sells N kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock. The package of chemical i contains a_i grams of the substance A and b_i grams of the substance B, and is sold for c_i yen (the currency of Japan). Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance C. Find the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C by purchasing any combination of packages at the pharmacy, report that fact. | ['n, ma, mb = map(int,input().split())\nINF = 10000\nmaxa = 0\nmaxb = 0\nmaxc = 0\nmedi = []\nfor i in range(n):\n a, b, c = map(int,input().split())\n maxa = max(maxa, a)\n maxb = max(maxb, b)\n maxc = max(maxc, c)\n medi.append([a, b, c])\ndp = [[[INF for k in range(maxb+1)] for j in range(maxa+1)] for i in range(n+1)]\ndp[0][0][0] = 0\nfor i in range(n):\n for x in range(maxa+1):\n for y in range(maxb+1):\n if dp[i][x][y] == INF:\n continue\n dp[i + 1][x][y] = min(dp[i + 1][x][y], dp[i][x][y])\n a, b, c = medi[i]\n if x + a <= maxa and y + b <= maxb:\n dp[i + 1][x + a][y + b] = min(dp[i][x][y] + c, dp[i + 1][x + a][y + b])\n\nt = 1\nok = False\nans = INF\nwhile t*ma <= maxa and t*mb <= maxb:\n print(t*ma,maxa,t*mb,maxb)\n if dp[n][t*ma][t*mb] < INF:\n ans = min(ans, dp[n][t*ma][t*mb])\n ok = True\n t += 1\n \nprint(ans if ok else -1)', 'print(-1)', 'n, ma, mb = map(int,input().split())\nINF = 10**6\nabmax = 10\nnmax = 40\nmedi = []\nsumb = 0\nsuma = 0\nfor i in range(n):\n a, b, c = map(int,input().split())\n suma += a\n sumb += b\n medi.append([a,b,c])\ndp = [[[INF for k in range(nmax*abmax+1)] for j in range(nmax*abmax+1)] for i in range(nmax+1)]\ndp[0][0][0] = 0\nfor i in range(n):\n a, b, c = medi[i]\n for x in range(suma+1):\n for y in range(sumb+1):\n if dp[i][x][y] == INF:\n continue\n if x + a <= suma + 1 and y + b <= sumb + 1:\n dp[i + 1][x][y] = min(dp[i + 1][x][y], dp[i][x][y])\n dp[i + 1][x + a][y + b] = min(dp[i][x][y] + c, dp[i + 1][x + a][y + b])\n\nt = 1\nok = False\nans = INF\nfor ca in range(1,nmax*abmax+1):\n for cb in range(1,nmax*abmax+1):\n if ma*cb == mb*ca:\n ans = min(ans, dp[n][ca][cb])\n \nprint(ans if ans != INF else -1)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s325765727', 's591041564', 's425458242'] | [3188.0, 2940.0, 60016.0] | [21.0, 17.0, 1120.0] | [937, 9, 898] |
p03806 | u595289165 | 2,000 | 262,144 | Dolphin is planning to generate a small amount of a certain chemical substance C. In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of M_a:M_b. He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy. The pharmacy sells N kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock. The package of chemical i contains a_i grams of the substance A and b_i grams of the substance B, and is sold for c_i yen (the currency of Japan). Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance C. Find the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C by purchasing any combination of packages at the pharmacy, report that fact. | ['import numpy as np\nn, ma, mb = map(int, input().split())\nr = 10 * n + 6\ninf = 10**5\ndp = np.full((n+1, r, r), inf)\ndp[0][0][0] = 0\nfor i in range(n):\n a, b, c = map(int, input().split())\n for j in range(r):\n for k in range(r):\n if j + a < r and k + b < r:\n dp[i+1][j+a][k+b] = min(\n dp[i][j][k] + c, dp[i][j+a][k+b]\n )\n dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k])\n\nans = inf\nx, y = 0, 0\nfor i in range(1, n+1):\n while True:\n x += ma\n y += mb\n if x < r and y < r:\n ans = min(ans, dp[i][x][y])\n else:\n break\nif ans == inf:\n print(-1)\nelse:\n print(int(ans))', 'import numpy as np\nn, ma, mb = map(int, input().split())\nr = 10 * n + 6\ninf = 10**5\ndp = np.full((n+1, r, r), inf)\ndp[0][0][0] = 0\nfor i in range(n):\n a, b, c = map(int, input().split())\n dp[i+1][a:, b:] = np.minimum(\n dp[i][:r-a, :r-b] + c, dp[i][a:, b:]\n )\n dp[i+1] = np.minimum(dp[i+1], dp[i])\n\nans = inf\nx, y = 0, 0\nwhile True:\n x += ma\n y += mb\n if x < r and y < r:\n ans = min(ans, dp[n][x][y])\n else:\n break\nif ans == inf:\n print(-1)\nelse:\n print(int(ans))'] | ['Wrong Answer', 'Accepted'] | ['s240895605', 's529871897'] | [67304.0, 69756.0] | [2109.0, 241.0] | [701, 513] |
p03806 | u603253967 | 2,000 | 262,144 | Dolphin is planning to generate a small amount of a certain chemical substance C. In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of M_a:M_b. He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy. The pharmacy sells N kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock. The package of chemical i contains a_i grams of the substance A and b_i grams of the substance B, and is sold for c_i yen (the currency of Japan). Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance C. Find the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C by purchasing any combination of packages at the pharmacy, report that fact. | ["from collections import defaultdict\n\nMAX = 40001\n\n\ndef main():\n N, Ma, Mb = [int(a) for a in input().split()]\n\n abc = [\n [int(a) for a in input().split()]\n for _ in range(N)\n ]\n\n dp = [\n [\n [MAX for b in range(10 * N + 1)]\n for a in range(10 * N + 1)\n ]\n for i in range(N)\n ] \n\n a, b, c = abc[0]\n dp[0][a][b] = c\n dp[0][0][0] = 0\n\n for i in range(1, N):\n a, b, c = abc[i]\n for j in range(10 * N):\n for k in range(10 * N):\n tukawanai = dp[i - 1][j][k]\n if j - a >= 0 and k - b >= 0 and dp[i - 1][j - a][k - b] != MAX:\n tukau = dp[i - 1][j - a][k - b] + c\n dp[i][j][k] = min(tukawanai, tukau)\n else:\n dp[i][j][k] = tukawanai\n\n res = MAX\n l = dp[-1]\n for a in range(10 * N):\n aa = a * Mb\n if aa % Ma != 0:\n continue\n b = aa // Ma\n if b >= len(l[a]):\n continue\n c = l[a][b]\n res = min(res, c)\n\n if res == MAX:\n res = -1\n print(res)\n\n\nif __name__ == '__main__':\n main()\n", "from collections import defaultdict\n\nMAX = 40001\n\n\ndef main():\n N, Ma, Mb = [int(a) for a in input().split()]\n\n abc = [\n [int(a) for a in input().split()]\n for _ in range(N)\n ]\n\n dp = [\n [\n [MAX for b in range(10 * N + 1)]\n for a in range(10 * N + 1)\n ]\n for i in range(N)\n ] \n\n A, B, C = abc[0]\n # dp[0][a][b] = c\n # dp[0][0][0] = 0\n\n mem = {(0, A, B): C, (0, 0, 0): 0}\n\n def solve(i, a, b):\n if (i, a, b) in mem:\n return mem[(i, a, b)]\n if i == 0:\n return MAX\n ai, bi, ci = abc[i]\n tukawanai = solve(i - 1, a, b)\n if a - ai >= 0 and b - bi >= 0:\n pre = solve(i - 1, a - ai, b - bi)\n if pre != MAX:\n mem[(i, a, b)] = min(tukawanai, pre + ci)\n return mem[(i, a, b)]\n mem[(i, a, b)] = tukawanai\n return mem[(i, a, b)]\n\n res = MAX\n for a in range(1, 10 * N + 1):\n aa = a * Mb\n if aa % Ma != 0:\n continue\n b = aa // Ma\n if b >= 10 * N + 1:\n continue\n c = solve(N - 1, a, b)\n res = min(res, c)\n\n if res == MAX:\n res = -1\n print(res)\n\n\nif __name__ == '__main__':\n main()\n"] | ['Wrong Answer', 'Accepted'] | ['s496461499', 's722695264'] | [56532.0, 182224.0] | [2107.0, 1828.0] | [1251, 1348] |
p03806 | u658993896 | 2,000 | 262,144 | Dolphin is planning to generate a small amount of a certain chemical substance C. In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of M_a:M_b. He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy. The pharmacy sells N kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock. The package of chemical i contains a_i grams of the substance A and b_i grams of the substance B, and is sold for c_i yen (the currency of Japan). Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance C. Find the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C by purchasing any combination of packages at the pharmacy, report that fact. | ['print(-1)', 'N,Ma,Mb=list(map(int,input().split()))\n\nmix=set([(0,0)])\nans=10**9\ncost={(0,0):0}\nfor i in range(N):\n a,b,c=list(map(int,input().split()))\n tmp=mix.copy()\n for x in tmp:\n d=x[0]+a\n e=x[1]+b\n f=min(cost.get((d,e),10**9),cost[x]+c)\n cost[(d,e)]=f\n mix.add((d, e))\n if d*Mb==e*Ma and f<ans:\n ans=f\nprint(cost)\nprint(mix)\nif ans==10**9:\n ans=-1\nprint(ans)', 'N,Ma,Mb=list(map(int,input().split()))\n\nmix=set([(0,0)])\nans=10**9\ncost={(0,0):0}\nfor i in range(N):\n a,b,c=list(map(int,input().split()))\n tmp=mix.copy()\n tmp2=cost.copy()\n for x in tmp:\n d=x[0]+a\n e=x[1]+b\n f=min(tmp2.get((d,e),10**9),tmp2[x]+c)\n cost[(d,e)]=f\n mix.add((d, e))\n if d*Mb==e*Ma and f<ans:\n ans=f\n"""\nprint(cost)\nprint(mix)\n"""\nif ans==10**9:\n ans=-1\nprint(ans)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s520155711', 's581353161', 's013236009'] | [2940.0, 10060.0, 14232.0] | [18.0, 407.0, 428.0] | [9, 416, 445] |
p03806 | u682985065 | 2,000 | 262,144 | Dolphin is planning to generate a small amount of a certain chemical substance C. In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of M_a:M_b. He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy. The pharmacy sells N kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock. The package of chemical i contains a_i grams of the substance A and b_i grams of the substance B, and is sold for c_i yen (the currency of Japan). Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance C. Find the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C by purchasing any combination of packages at the pharmacy, report that fact. | ["n, ma, mb = map(int, f.readline().split())\na, b, c = [], [], []\nfor _ in range(n):\n at, bt, ct = map(int, f.readline().split())\n a.append(at)\n b.append(bt)\n c.append(ct)\n \ndp = [[float('inf') for _ in range(n*mb + 1)] for _ in range(n*ma + 1)]\ndp[0][0] = 0\nused = [[0, 0]]\n\nfor i in range(n):\n add_used = []\n for at, bt in used:\n if at+a[i] <= n and bt+b[i] <= n:\n if dp[at+a[i]][bt+b[i]] == float('inf'):\n add_used.append([at+a[i], bt+b[i]])\n \n dp[at+a[i]][bt+b[i]] = min(dp[at][bt]+c[i], dp[at+a[i]][bt+b[i]])\n \n used += add_used\n\nif dp[-1][-1] == float('inf'):\n print(-1)\nelse :\n print(dp[-1][-1])", "import copy\nn, ma, mb = map(int, input().split())\na, b, c = [0]*n, [0]*n, [0]*n\nfor i in range(n):\n a[i], b[i], c[i] = map(int, input().split())\n \ndp = [[float('inf')] * (sum(b)+1) for _ in range(sum(a)+1)]\ndp[0][0] = 0\nstep = set([(0, 0)])\n\nfor i in range(n):\n ai, bi = a[i], b[i]\n\n s = step.copy()\n tempdp = copy.deepcopy(dp)\n for si in s: \n if dp[si[0]+ai][si[1]+bi] > dp[si[0]][si[1]] + c[i]:\n tempdp[si[0]+ai][si[1]+bi] = dp[si[0]][si[1]] + c[i]\n step.add((si[0]+ai, si[1]+bi))\n \n dp = tempdp[:]\n#28 20\n\nans = float('inf')\nfor i in range(1, min(sum(a)//ma, sum(b)//mb)+1):\n ans = min(ans, dp[ma*i][mb*i])\n \nif ans == float('inf'): print(-1)\nelse : print(ans)"] | ['Runtime Error', 'Accepted'] | ['s892366979', 's946646073'] | [3064.0, 9308.0] | [17.0, 1845.0] | [692, 725] |
p03806 | u683134447 | 2,000 | 262,144 | Dolphin is planning to generate a small amount of a certain chemical substance C. In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of M_a:M_b. He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy. The pharmacy sells N kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock. The package of chemical i contains a_i grams of the substance A and b_i grams of the substance B, and is sold for c_i yen (the currency of Japan). Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance C. Find the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C by purchasing any combination of packages at the pharmacy, report that fact. | ['global N\nglobal Nlist\nglobal Ma\nglobal Mb\nglobal minicost\nminicost = 10000000\nN, Ma, Mb = map(int,input().split()) \nNlist = []\nfor i in range(N):\n a,b,c = map(int,input().split())\n Nlist.append([a,b,c])\ndef dvector(Masum,Mbsum,cost,vector):\n print(vector)\n global Ma\n global Mb\n global Nlist\n global minicost\n if len(vector) == len(Nlist):\n return 0\n dvector(Masum,Mbsum,cost,vector+[0])\n Masum+= Nlist[len(vector)-1][0]\n Mbsum+= Nlist[len(vector)-1][1]\n cost += Nlist[len(vector)-1][2]\n if Mbsum > 0:\n if Masum/Mbsum == Ma/Mb:\n if minicost > cost:\n minicost = cost\n print(vector,cost,minicost)\n if cost < minicost:\n dvector(Masum,Mbsum,cost,vector+[1])\n return 0\n \ndvector(0,0,0,[])\nif minicost == 10000000:\n print("-1")\nelse:\n print(minicost)', 'global N\nglobal Nlist\nglobal Ma\nglobal Mb\nglobal minicost\nminicost = 10000000\nN, Ma, Mb = map(int,input().split()) \nNlist = []\nfor i in range(N):\n a,b,c = map(int,input().split())\n Nlist.append([a,b,c])\n\ndef dvector(Masum,Mbsum,cost,vector):\n global Ma\n global Mb\n global Nlist\n global minicost\n if len(vector) == len(Nlist):\n return 0\n dvector(Masum,Mbsum,cost,vector+[0])\n Masum+= Nlist[len(vector)-1][0]\n Mbsum+= Nlist[len(vector)-1][1]\n cost += Nlist[len(vector)-1][2]\n if Mbsum > 0:\n if Masum/Mbsum == Ma/Mb:\n if minicost > cost:\n minicost = cost\n if cost < minicost:\n dvector(Masum,Mbsum,cost,vector+[1])\n return 0\n \ndvector(0,0,0,[])\nif minicost == 10000000:\n print("-1")\nelse:\n print(minicost)'] | ['Wrong Answer', 'Accepted'] | ['s590162628', 's246196926'] | [37492.0, 3064.0] | [1598.0, 249.0] | [848, 799] |
p03806 | u683479402 | 2,000 | 262,144 | Dolphin is planning to generate a small amount of a certain chemical substance C. In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of M_a:M_b. He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy. The pharmacy sells N kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock. The package of chemical i contains a_i grams of the substance A and b_i grams of the substance B, and is sold for c_i yen (the currency of Japan). Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance C. Find the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C by purchasing any combination of packages at the pharmacy, report that fact. | ['# ABC54 D\nn,ma,mb = map(int, input().split())\na = []\nb = []\nc = []\nfor i in range(N):\n ai,bi,ci = map(int, input().split())\n a.append(ai)\n b.append(bi)\n c.append(ci)\n \nmax_sum = n * 10\nmax_cost = 100000000\ndp = [[[max_cost for k in range(n+1)] for j in range(max_sum+1)] for i in range(max_sum+1)]\n\ndp[0][0][0] = 0\nfor i in range(n):\n for ca in range(max_sum+1):\n for cb in range(max_sum+1):\n if(dp[i][ca][cb] == max_cost):\n continue\n dp[i+1][ca][cb] = min(dp[i+1][ca][cb], dp[i][ca][cb])\n dp[i+1][ca+a[i]][cb+b[i]] = min(dp[i+1][ca+a[i]][cb+b[i]], dp[i][ca][cb]+c[i])\n\nans = max_cost\nfor ca in range(max_sum+1):\n for cb in range(max_sum+1):\n if(ca*mb == cb*ma):\n ans = min(ans, dp[n][ca][cb])\n\nif(ans == max_cost):\n print(-1)\nelse:\n print(ans)', '# ABC54 D\nn,ma,mb = map(int, input().split())\na = []\nb = []\nc = []\nfor i in range(N):\n ai,bi,ci = map(int, input().split())\n a.append(ai)\n b.append(bi)\n c.append(ci)\n \nmax_sum = n * 10\nmax_cost = 100000000\ndp = [[[max_cost for k in range(max_sum+1)] for j in range(max_sum+1)] for i in range(n+1)]\n\ndp[0][0][0] = 0\nfor i in range(n):\n for ca in range(max_sum+1):\n for cb in range(max_sum+1):\n if(dp[i][ca][cb] == max_cost):\n continue\n dp[i+1][ca][cb] = min(dp[i+1][ca][cb], dp[i][ca][cb])\n dp[i+1][ca+a[i]][cb+b[i]] = min(dp[i+1][ca+a[i]][cb+b[i]], dp[i][ca][cb]+c[i])\n\nans = max_cost\nfor ca in range(1,max_sum+1):\n for cb in range(1,max_sum+1):\n if(ca*mb == cb*ma):\n ans = min(ans, dp[n][ca][cb])\n\nif(ans == max_cost):\n print(-1)\nelse:\n print(ans)', '# ABC54 D\nn,ma,mb = map(int, input().split())\na = []\nb = []\nc = []\nfor i in range(N):\n ai,bi,ci = map(int, input().split())\n a.append(ai)\n b.append(bi)\n c.append(ci)\n \nmax_sum = n * 10\nmax_cost = 100000000\ndp = [[[max_cost for k in range(n+1)] for j in range(max_sum+1)] for i in range(max_sum+1)]\n\ndp[0][0][0] = 0\nfor i in range(n):\n for ca in range(max_sum+1):\n for cb in range(max_sum+1):\n if(dp[i][ca][cb] == max_cost):\n continue\n dp[i+1][ca][cb] = min(dp[i+1][ca][cb], dp[i][ca][cb])\n dp[i+1][ca+a[i]][cb+b[i]] = min(dp[i+1][ca+a[i]][cb+b[i]], dp[i][ca][cb]+c[i])\n\nans = max_cost\nfor ca in range(max_sum+1):\n for cb in range(max_sum+1):\n if(ca*mb == cb*ma):\n ans = min(ans, dp[n][ca][cb])\n\nif(ans == max_cost):\n print(-1)\nelse:\n print(ans)', '# ABC54 D\nn,ma,mb = map(int, input().split())\na = []\nb = []\nc = []\nfor i in range(n):\n ai,bi,ci = map(int, input().split())\n a.append(ai)\n b.append(bi)\n c.append(ci)\n \nmax_sum = n * 10\nmax_cost = 100000000\ndp = [[[max_cost for k in range(max_sum+1)] for j in range(max_sum+1)] for i in range(n+1)]\n\ndp[0][0][0] = 0\nfor i in range(n):\n for ca in range(max_sum+1):\n for cb in range(max_sum+1):\n if(dp[i][ca][cb] == max_cost):\n continue\n dp[i+1][ca][cb] = min(dp[i+1][ca][cb], dp[i][ca][cb])\n dp[i+1][ca+a[i]][cb+b[i]] = min(dp[i+1][ca+a[i]][cb+b[i]], dp[i][ca][cb]+c[i])\n\nans = max_cost\nfor ca in range(1,max_sum+1):\n for cb in range(1,max_sum+1):\n if(ca*mb == cb*ma):\n ans = min(ans, dp[n][ca][cb])\n\nif(ans == max_cost):\n print(-1)\nelse:\n print(ans)'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s793797912', 's924860777', 's944875373', 's690541993'] | [3444.0, 3064.0, 3192.0, 60780.0] | [25.0, 17.0, 17.0, 1773.0] | [844, 848, 844, 848] |
p03806 | u729707098 | 2,000 | 262,144 | Dolphin is planning to generate a small amount of a certain chemical substance C. In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of M_a:M_b. He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy. The pharmacy sells N kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock. The package of chemical i contains a_i grams of the substance A and b_i grams of the substance B, and is sold for c_i yen (the currency of Japan). Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance C. Find the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C by purchasing any combination of packages at the pharmacy, report that fact. | ['n,ma,mb = (int(i) for i in input().split())\nx = [[int(i) for i in input().split()] for i in range(n)]\ndp = [[float("inf") for i in range(10*n+1)] for i in range(10*n+1)]\ndp[0][0],ans = 0,float("inf")\nfor i in range(n):\n\tfor j in range(10*(i-1)+1):\n\t\tfor k in range(10*(i-1)+1):\n\t\t\tif dp[j][k]!=float("inf"): dp[j+x[i][0]][k+x[i][1]] = min(dp[j][k]+x[i][2],dp[j+x[i][0]][k+x[i][1]])\nfor i in range(ma,10*n+1,ma):\n\tif i*mb//ma<=10*n: ans=min(ans,dp[i][i*mb//ma])\nif ans==float("inf"): print(-1)\nelse: print(ans)', 'n, ma, mb = map(int, input().split())\nINF = float("inf")\ndp = [[[INF for i in range(10*n+1)] for i in range(10*n+1)] for i in range(n+1)]\ndp[0][0][0],ans = 0,INF\nfor i in range(1,n+1):\n a,b,c = (int(l) for l in input().split())\n for j in range(10*(i-1)+1):\n for k in range(10*(i-1)+1):\n if dp[i-1][j][k] != INF:\n dp[i][j][k] = min(dp[i][j][k], dp[i-1][j][k])\n dp[i][j+a][k+b] = min(dp[i][j+a][k+b], dp[i-1][j][k]+c)\nfor i in range(ma,10*n+1,ma):\n\tif i*mb//ma<=10*n: ans=min(ans,dp[n][i][i*mb//ma])\nif ans==INF: print(-1)\nelse: print(ans)'] | ['Wrong Answer', 'Accepted'] | ['s073237409', 's513358291'] | [11876.0, 60020.0] | [1983.0, 1153.0] | [509, 587] |
p03806 | u780475861 | 2,000 | 262,144 | Dolphin is planning to generate a small amount of a certain chemical substance C. In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of M_a:M_b. He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy. The pharmacy sells N kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock. The package of chemical i contains a_i grams of the substance A and b_i grams of the substance B, and is sold for c_i yen (the currency of Japan). Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance C. Find the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C by purchasing any combination of packages at the pharmacy, report that fact. | ["n, ma, mb = [int(i) for i in input().split()]\nlst = [[int(i) for i in input().split()] for _ in range(n)]\nlst.sort(key=lambda x: x[2])\n\ndef push(k,v):\n if k in dic:\n dic[k] = min(dic[k],v)\n else:\n dic[k] = v\n\n\nfor i in lst:\n k, v = i[0] * mb - i[1] * ma, i[2]\n l = [[j, dic[j]] for j in dic]\n for item in l:\n push(item[0] + k, item[1] + v)\n push(k, v)\n\nprint(dic[0] if 0 in dic else '-1')", "n, ma, mb = [int(i) for i in input().split()]\nlst = [[int(i) for i in input().split()] for _ in range(n)]\nlst.sort(key=lambda x: x[2])\ndic = {}\ndef push(k,v):\n if k in dic:\n dic[k] = min(dic[k],v)\n else:\n dic[k] = v\n\n\nfor i in lst:\n k, v = i[0] * mb - i[1] * ma, i[2]\n l = [[j, dic[j]] for j in dic]\n for item in l:\n push(item[0] + k, item[1] + v)\n push(k, v)\n\nprint(dic[0] if 0 in dic else '-1')"] | ['Runtime Error', 'Accepted'] | ['s431241027', 's935184754'] | [3064.0, 3572.0] | [17.0, 41.0] | [427, 435] |
p03806 | u785989355 | 2,000 | 262,144 | Dolphin is planning to generate a small amount of a certain chemical substance C. In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of M_a:M_b. He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy. The pharmacy sells N kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock. The package of chemical i contains a_i grams of the substance A and b_i grams of the substance B, and is sold for c_i yen (the currency of Japan). Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance C. Find the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C by purchasing any combination of packages at the pharmacy, report that fact. | ['N,A,B = list(map(int,input().split()))\n\nitem=[]\nfor i in range(N):\n a,b,c = list(map(int,input().split()))\n item.append([a,b,c])\n\nD = [[10**27 for i in range(401)] for j in range(401)]\nD[0][0] = 0\nfor i in range(N):\n for j in range(401):\n for k in range(401):\n if D[j][k]<10**27:\n D[j+item[i][0]][k+item[i][1]] = min(D[j+item[i][0]][k+item[i][1]],D[j][k]+item[i][2])\n\ni=1\nmin_cost=10**27\nwhile A*i<=400 and B*i<=400:\n min_cost = min(D[A*i][B*i],min_cost)\n i+=1\nif min_cost==10**27:\n\tprint(-1)\nelse:\n\tprint(min_cost)', 'N,M=list(map(int,input().split()))\n\ne_list = []\nfor i in range(M):\n a,b,c = list(map(int,input().split()))\n e_list.append([a-1,b-1,-c])\n\nvi=0\nmin_dis_list = [10**27 for i in range(N)]\nmin_dis_list[vi] = 0\nprev_list = [-1 for i in range(N)]\n\nfor i in range(N-1):\n for e in e_list:\n u,v,d = e\n if min_dis_list[v]>min_dis_list[u]+d:\n min_dis_list[v]=min_dis_list[u]+d\n prev_list[v]=u\n\nneg_loop_flag=False\nfor e in e_list:\n u,v,d = e\n if min_dis_list[u] + d < min_dis_list[v]:\n neg_loop_flag=True\n break\nif neg_loop_flag:\n print("inf")\nelse:\n print(-min_dis_list[N-1])', '\nN,A,B = list(map(int,input().split()))\n\nitem=[]\nfor i in range(N):\n a,b,c = list(map(int,input().split()))\n item.append([a,b,c])\n\nD = [[[10**27 for i in range(401)] for j in range(401)] for k in range(N+1)]\nD[0][0][0] = 0\nfor i in range(N):\n for j in range(401):\n for k in range(401):\n if D[i][j][k]<10**26:\n D[i+1][j][k]=min(D[i+1][j][k],D[i][j][k])\n D[i+1][j+item[i][0]][k+item[i][1]] = min(D[i+1][j+item[i][0]][k+item[i][1]],D[i][j][k]+item[i][2])\n\ni=1\nmin_cost=10**27\nwhile A*i<=400 and B*i<=400:\n min_cost = min(D[A*i][B*i],min_cost)\n i+=1\nif min_cost==10**27:\n\tprint(-1)\nelse:\n\tprint(min_cost)', '\nN,A,B = list(map(int,input().split()))\n\nitem=[]\nfor i in range(N):\n a,b,c = list(map(int,input().split()))\n item.append([a,b,c])\n\nD = [[[10**27 for i in range(401)] for j in range(401)] for k in range(N+1)]\nD[0][0] = 0\nfor i in range(N):\n for j in range(401):\n for k in range(401):\n if D[j][k]<10**26:\n D[i+1][j][k]=min(D[i+1][j][k],D[i][j][k])\n D[i+1][j+item[i][0]][k+item[i][1]] = min(D[i+1][j+item[i][0]][k+item[i][1]],D[i][j][k]+item[i][2])\n\ni=1\nmin_cost=10**27\nwhile A*i<=400 and B*i<=400:\n min_cost = min(D[A*i][B*i],min_cost)\n i+=1\nif min_cost==10**27:\n\tprint(-1)\nelse:\n\tprint(min_cost)', '\nN,A,B = list(map(int,input().split()))\n\nitem=[]\nfor i in range(N):\n a,b,c = list(map(int,input().split()))\n item.append([a,b,c])\n\nD = [[[10**27 for i in range(401)] for j in range(401)] for k in range(N+1)]\nD[0][0][0] = 0\nfor i in range(N):\n for j in range(401):\n for k in range(401):\n if D[i][j][k]<10**26:\n D[i+1][j][k]=min(D[i+1][j][k],D[i][j][k])\n D[i+1][j+item[i][0]][k+item[i][1]] = min(D[i+1][j+item[i][0]][k+item[i][1]],D[i][j][k]+item[i][2])\n\ni=1\nmin_cost=10**27\nwhile A*i<=400 and B*i<=400:\n min_cost = min(D[N][A*i][B*i],min_cost)\n i+=1\nif min_cost==10**27:\n\tprint(-1)\nelse:\n\tprint(min_cost)'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s484633278', 's855371918', 's922906438', 's929101467', 's775805195'] | [4340.0, 3064.0, 60016.0, 56436.0, 61168.0] | [45.0, 18.0, 1925.0, 361.0, 1928.0] | [563, 635, 663, 657, 666] |
p03806 | u826438738 | 2,000 | 262,144 | Dolphin is planning to generate a small amount of a certain chemical substance C. In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of M_a:M_b. He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy. The pharmacy sells N kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock. The package of chemical i contains a_i grams of the substance A and b_i grams of the substance B, and is sold for c_i yen (the currency of Japan). Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance C. Find the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C by purchasing any combination of packages at the pharmacy, report that fact. | ['N,Ma,Mb=map(int,input().split())\n\ndp = [[10**18 for _ in range(401)] for _ in range(401)]\n\ndp[0][0]=0\nfor i in range(N):\n a,b,c=map(int,input().split())\n for ca in range(361, -1, -1):\n for cb in range(361, -1, -1):\n dp[ca+a][cb+b] = min(dp[ca+a][cb+b],dp[ca][cb]+c)\n ', 'N,Ma,Mb=map(int,input().split())\n\nA,B,C = [],[],[]\nfor i in range(N):\n a,b,c=map(int,input().split())\n A += [a]\n B += [b]\n C += [c]\n\ndp = [[[10**18 for _ in range(401)] for _ in range(401)] for _ in range(N+1)]\n\ndp[0][0][0]=0\nfor i in range(N):\n for ca in range(i * 10):\n for cb in range(i * 10):\n dp[i+1][ca][cb] = min(dp[i+1][ca][cb],dp[i][ca][cb])\n dp[i+1][ca+A[i]][cb+B[i]] = min(dp[i+1][ca+A[i]][cb+B[i]],dp[i][ca][cb]+C[i])\n\nans = 10**18\nfor ca in range(401):\n for cb in range(401):\n if not ca*Mb == cb*Ma or ca == 0:\n continue\n if ans > dp[N][ca][cb]:\n ans = dp[N][ca][cb]\n \nif ans == 10**18:\n print(-1)\nelse:\n print(ans)\n', 'N,Ma,Mb=map(int,input().split())\n\ndp = [[10**18 for _ in range(401)] for _ in range(401)]\n\ndp[0][0]=0\nfor i in range(N):\n a,b,c=map(int,input().split())\n for ca in range(i * 10, -1, -1):\n for cb in range(i * 10, -1, -1):\n dp[ca+a][cb+b] = min(dp[ca+a][cb+b],dp[ca][cb]+c)\n\nans = 10**18\nfor ca in range(401):\n for cb in range(401):\n if not ca*Mb == cb*Ma or ca == 0:\n continue\n if ans > dp[ca][cb]:\n ans = dp[ca][cb]\n \nif ans == 10**18:\n print(-1)\nelse:\n print(ans)\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s087651252', 's218788137', 's965309213'] | [4496.0, 58356.0, 4852.0] | [2104.0, 2107.0, 1526.0] | [298, 725, 541] |
p03806 | u844789719 | 2,000 | 262,144 | Dolphin is planning to generate a small amount of a certain chemical substance C. In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of M_a:M_b. He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy. The pharmacy sells N kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock. The package of chemical i contains a_i grams of the substance A and b_i grams of the substance B, and is sold for c_i yen (the currency of Japan). Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance C. Find the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C by purchasing any combination of packages at the pharmacy, report that fact. | ['N, Ma, Mb = [int(_) for _ in input().split()]\nABC = [[int(_) for _ in input().split()] for _ in range(N)]\ndp = {}\ndp[0] = {}\ndp[0][ABC[0][0] + 1000 * ABC[0][1]] = ABC[0][2]\nans = 5000\nfor i in range(N - 1):\n for ab in dp[i].keys():\n a = ab % 1000\n b = ab // 1000\n if a * Mb == b * Ma:\n ans = min(ans, dp[i][ab])\n dp[i + 1] = dp.get(i + 1, {})\n dp[i + 1][a + ABC[i + 1][0] + 1000 * (b + ABC[i + 1][1])] = min(\n dp[i][ab] + ABC[i + 1][2], dp[i].get(\n a + ABC[i + 1][0] + 1000 * (b + ABC[i + 1][1]), 0))\nfor ab in dp[N - 1].keys():\n a = ab % 1000\n b = ab // 1000\n if a * Mb == b * Ma:\n ans = min(ans, dp[N - 1][ab])\nif ans == 5000:\n print(-1)\nelse:\n print(ans)', 'N, Ma, Mb = [int(_) for _ in input().split()]\nABC = [[int(_) for _ in input().split()] for _ in range(N)]\ndp = {}\ndp[ABC[0][0] + 1000 * ABC[0][1]] = ABC[0][2]\nans = 5000\nfor i in range(N - 1):\n dp_old = dp.copy()\n for ab in dp_old.keys():\n a = ab % 1000\n b = ab // 1000\n if a * Mb == b * Ma:\n ans = min(ans, dp_old[ab])\n dp[a + ABC[i + 1][0] + 1000 * (b + ABC[i + 1][1])] = min(\n dp_old[ab] + ABC[i + 1][2],\n dp_old.get(a + ABC[i + 1][0] + 1000 * (b + ABC[i + 1][1]), 5000))\n print(dp)\nfor ab in dp.keys():\n a = ab % 1000\n b = ab // 1000\n if a * Mb == b * Ma:\n ans = min(ans, dp[ab])\nif ans == 5000:\n print(-1)\nelse:\n print(ans)', 'N, Ma, Mb = [int(_) for _ in input().split()]\nABC = [[int(_) for _ in input().split()] for _ in range(N)]\ndp = {}\ndp[0] = 0\ndp[ABC[0][0] + 1000 * ABC[0][1]] = ABC[0][2]\nans = 5000\nfor i in range(N - 1):\n dp_old = dp.copy()\n for ab in dp_old.keys():\n a = ab % 1000\n b = ab // 1000\n if a * Mb == b * Ma > 0:\n ans = min(ans, dp_old[ab])\n dp[a + ABC[i + 1][0] + 1000 * (b + ABC[i + 1][1])] = min(\n dp_old[ab] + ABC[i + 1][2],\n dp_old.get(a + ABC[i + 1][0] + 1000 * (b + ABC[i + 1][1]), 5000))\nfor ab in dp.keys():\n a = ab % 1000\n b = ab // 1000\n if a * Mb == b * Ma > 0:\n ans = min(ans, dp[ab])\nif ans == 5000:\n print(-1)\nelse:\n print(ans)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s601525214', 's866380497', 's062343526'] | [3064.0, 12284.0, 9932.0] | [19.0, 459.0, 457.0] | [754, 720, 724] |
p03806 | u942033906 | 2,000 | 262,144 | Dolphin is planning to generate a small amount of a certain chemical substance C. In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of M_a:M_b. He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy. The pharmacy sells N kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock. The package of chemical i contains a_i grams of the substance A and b_i grams of the substance B, and is sold for c_i yen (the currency of Japan). Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance C. Find the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C by purchasing any combination of packages at the pharmacy, report that fact. | ['N,Ma,Mb = map(int,input().split())\nfirst_half = []\nlast_half = []\nfor i in range(N):\n\ta,b,c = map(int,input().split())\n\tif i < N // 2:\n\t\tfirst_half.append((a,b,c))\n\telse:\n\t\tlast_half.append((a,b,c))\n\nfirst_half_combination = {}\nlast_half_combination = {}\ndef make_all_combination(i,a,b,c,d_list,flag):\n\tif i == len(d_list) and c > 0:\n\t\tw = Ma * b - Mb * a\n\t\tif flag:\n\t\t\tif w not in first_half_combination or c < first_half_combination[w]:\n\t\t\t\tfirst_half_combination[w] = c\n\t\telse:\n\t\t\tif -w not in last_half_combination or c < last_half_combination[-w]:\n\t\t\t\tlast_half_combination[-w] = c\n\t\treturn\n\tmake_all_combination(i+1,a,b,c,d_list,flag)\n\tmake_all_combination(i+1,a+d_list[i][0],b+d_list[i][1],c+d_list[i][2],d_list,flag)\n\ndef search(w, lst):\n\tleft,right = 0, len(lst)\n\twhile left + 1 != right:\n\t\tp = (left + right) // 2\n\t\tif lst[p][0] < w:\n\t\t\tleft = p\n\t\telse:\n\t\t\tright = p\n\treturn left\nmake_all_combination(0,0,0,0,first_half,True)\nmake_all_combination(0,0,0,0,last_half,False)\n\nprint(first_half_combination)\nprint(last_half_combination)\nans = -1\nfor w in first_half_combination.keys():\n\tif w in last_half_combination:\n\t\tcost = first_half_combination[w] + last_half_combination[w]\n\t\tif w == 0:\n\t\t\tcost = min(first_half_combination[w], last_half_combination[w])\n\t\tif ans == -1 or cost < ans:\n\t\t\tans = cost\n\telif w == 0:\n\t\tcost = first_half_combination[w]\n\t\tif cost < ans:\n\t\t\tans = cost\nprint(ans)', 'N,Ma,Mb = map(int,input().split())\nfirst_half = []\nlast_half = []\nfor i in range(N):\n\ta,b,c = map(int,input().split())\n\tif i < N // 2:\n\t\tfirst_half.append((a,b,c))\n\telse:\n\t\tlast_half.append((a,b,c))\n\nfirst_half_combination = []\nlast_half_combination = []\ndef make_all_combination(i,a,b,c,d_list,c_list):\n\tif i == len(d_list):\n\t\tc_list.append((Ma * b - Mb * a, c))\n\t\treturn\n\tmake_all_combination(i+1,a,b,c,d_list,c_list)\n\tmake_all_combination(i+1,a+d_list[i][0],b+d_list[i][1],c+d_list[i][2],d_list,c_list)\n\ndef search(w, lst):\n\tleft,right = 0, len(lst)\n\twhile left + 1 != right:\n\t\tp = (left + right) // 2\n\t\tif lst[p][0] < w:\n\t\t\tleft = p\n\t\telse:\n\t\t\tright = p\n\treturn left\nmake_all_combination(0,0,0,0,first_half,first_half_combination)\nmake_all_combination(0,0,0,0,last_half,last_half_combination)\nfirst_half_combination.sort()\nlast_half_combination.sort()\n\nans_list = []\nfor (w,c) in first_half_combination:\n\tn = search(-w, last_half_combination)\n\tif last_half_combination[n][0] == -w:\n\t\tans_list.append(c + last_half_combination[n][1])\n\tif n+1 < len(last_half_combination) and last_half_combination[n+1][0] == -w:\n\t\tans_list.append(c + last_half_combination[n+1][1])\n\nif len(ans_list) > 0:\n\tprint(min(ans_list))\nelse:\n\tprint(-1)', 'N,Ma,Mb = map(int,input().split())\nfirst_half = []\nlast_half = []\nfor i in range(N):\n\ta,b,c = map(int,input().split())\n\tif i < N // 2:\n\t\tfirst_half.append((a,b,c))\n\telse:\n\t\tlast_half.append((a,b,c))\n\nfirst_half_combination = {}\nlast_half_combination = {}\ndef make_all_combination(i,a,b,c,d_list,flag):\n\tif i == len(d_list):\n\t\tif c == 0:\n\t\t\treturn\n\n\t\tw = Ma * b - Mb * a\n\t\tif flag:\n\t\t\tif w not in first_half_combination or c < first_half_combination[w]:\n\t\t\t\tfirst_half_combination[w] = c\n\t\telse:\n\t\t\tif -w not in last_half_combination or c < last_half_combination[-w]:\n\t\t\t\tlast_half_combination[-w] = c\n\t\treturn\n\tmake_all_combination(i+1,a,b,c,d_list,flag)\n\tmake_all_combination(i+1,a+d_list[i][0],b+d_list[i][1],c+d_list[i][2],d_list,flag)\n\nmake_all_combination(0,0,0,0,first_half,True)\nmake_all_combination(0,0,0,0,last_half,False)\n\nINF = 10**8\nf_0 = first_half_combination[0] if 0 in last_half_combination else INF\nl_0 = first_half_combination[0] if 0 in last_half_combination else INF\nans = min(f_0,l_0) if min(f_0,l_0) < INF else -1\nfor w in first_half_combination.keys():\n\tif w == 0:\n\t\tcontinue\n\tif w in last_half_combination:\n\t\tcost = first_half_combination[w] + last_half_combination[w]\n\t\tif w == 0:\n\t\t\tcost = min(first_half_combination[w], last_half_combination[w])\n\t\tif ans == -1 or cost < ans:\n\t\t\tans = cost\nprint(ans)', 'N,Ma,Mb = map(int,input().split())\nfirst_half = []\nlast_half = []\nfor i in range(N):\n\ta,b,c = map(int,input().split())\n\tif i < N // 2:\n\t\tfirst_half.append((a,b,c))\n\telse:\n\t\tlast_half.append((a,b,c))\n\nfirst_half_combination = {}\nlast_half_combination = {}\ndef make_all_combination(i,a,b,c,d_list,flag):\n\tif i == len(d_list):\n\t\tif c == 0:\n\t\t\treturn\n\n\t\tw = Ma * b - Mb * a\n\t\tif flag:\n\t\t\tif w not in first_half_combination or c < first_half_combination[w]:\n\t\t\t\tfirst_half_combination[w] = c\n\t\telse:\n\t\t\tif -w not in last_half_combination or c < last_half_combination[-w]:\n\t\t\t\tlast_half_combination[-w] = c\n\t\treturn\n\tmake_all_combination(i+1,a,b,c,d_list,flag)\n\tmake_all_combination(i+1,a+d_list[i][0],b+d_list[i][1],c+d_list[i][2],d_list,flag)\n\nmake_all_combination(0,0,0,0,first_half,True)\nmake_all_combination(0,0,0,0,last_half,False)\n\nINF = 10**8\nf_0 = first_half_combination[0] if 0 in first_half_combination else INF\nl_0 = last_half_combination[0] if 0 in last_half_combination else INF\nans = min(f_0,l_0) if min(f_0,l_0) < INF else -1\nfor w in first_half_combination.keys():\n\tif w == 0:\n\t\tcontinue\n\tif w in last_half_combination:\n\t\tcost = first_half_combination[w] + last_half_combination[w]\n\t\tif w == 0:\n\t\t\tcost = min(first_half_combination[w], last_half_combination[w])\n\t\tif ans == -1 or cost < ans:\n\t\t\tans = cost\nprint(ans)'] | ['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s024333021', 's280902982', 's676295028', 's768543337'] | [3964.0, 285788.0, 3188.0, 3188.0] | [80.0, 2122.0, 1739.0, 1801.0] | [1399, 1229, 1327, 1327] |
p03806 | u985443069 | 2,000 | 262,144 | Dolphin is planning to generate a small amount of a certain chemical substance C. In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of M_a:M_b. He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy. The pharmacy sells N kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock. The package of chemical i contains a_i grams of the substance A and b_i grams of the substance B, and is sold for c_i yen (the currency of Japan). Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance C. Find the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C by purchasing any combination of packages at the pharmacy, report that fact. | ['\nn, ma, mb = map(int, input().split())\na = [0] * n\nb = [0] * n\nc = [0] * n\nfor i in range(n):\n a[i], b[i], c[i] = map(int, input().split())\n\nM = 401\nINF = 10 ** 15\nmin_cost = dict()\nmin_cost[0, 0] = 0\n\nfor k in range(n):\n keys = min_cost.keys()\n for i, j in reversed(sorted(keys)):\n if i + a[k] < M and j + b[k] < M:\n cc = min_cost[i][j] + c[k]\n if cc < min_cost[i + a[k]][j + b[k]]:\n min_cost[i + a[k]][j + b[k]] = cc\n\nres = INF\nfor i in range(1, M):\n for j in range(1, M):\n if i * mb == j * ma:\n if min_cost[i][j] < res:\n res = min_cost[i][j]\n\nif res == INF:\n res = -1\nprint(res)', '\nn, ma, mb = map(int, input().split())\na = [0] * n\nb = [0] * n\nc = [0] * n\nfor i in range(n):\n a[i], b[i], c[i] = map(int, input().split())\n\nM = 401\nINF = 10 ** 15\nmin_cost = [[INF] * M for k in range(M)]\ns = set()\nmin_cost[0][0] = 0\ns.add((0, 0))\n\nfor k in range(n):\n ss = set(s)\n for i, j in reversed(sorted(s)):\n if i + a[k] < M and j + b[k] < M:\n cc = min_cost[i][j] + c[k]\n if cc < min_cost[i + a[k]][j + b[k]]:\n ss.add((i + a[k], j + b[k]))\n min_cost[i + a[k]][j + b[k]] = cc\n s = ss\n\nres = INF\nfor i in range(1, M):\n for j in range(1, M):\n if i * mb == j * ma:\n if min_cost[i][j] < res:\n res = min_cost[i][j]\n\nif res == INF:\n res = -1\nprint(res)\n'] | ['Runtime Error', 'Accepted'] | ['s661714904', 's140047936'] | [3064.0, 8504.0] | [17.0, 460.0] | [673, 763] |
p03806 | u995062424 | 2,000 | 262,144 | Dolphin is planning to generate a small amount of a certain chemical substance C. In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of M_a:M_b. He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy. The pharmacy sells N kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock. The package of chemical i contains a_i grams of the substance A and b_i grams of the substance B, and is sold for c_i yen (the currency of Japan). Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance C. Find the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C by purchasing any combination of packages at the pharmacy, report that fact. | ['def main():\n N, Ma, Mb = map(int, input().split())\n yakuhin = []\n sa = 0\n sb = 0\n for i in range(N):\n yakuhin.append(list(map(int, input().split())))\n sa += yakuhin[i][0]\n sb += yakuhin[i][1]\n \n INF = 10**15\n DP = [[[INF for _ in range(sb+1)] for _ in range(sa+1)] for _ in range(N+1)]\n DP[0][0][0] = 0\n \n for i in range(N):\n for j in range(sa+1):\n for k in range(sb+1):\n if(j >= yakuhin[i][0] and k >= yakuhin[i][1]):\n DP[i+1][j][k] = min(DP[i][j-yakuhin[i][0]][k-yakuhin[i][1]], DP[i][j-yakuhin[i][0]][k-yakuhin[i][1]]+yakuhin[i][2])\n else:\n DP[i+1][j][k] = min(DP[i+1][j][k], DP[i][j][k])\n \n ans = INF\n for i in range(1, N):\n for j in range(1, sa+1):\n for k in range(1, sb+1):\n if(j*Mb == k*Ma):\n ans = min(ans, DP[i][j][k]) \n \n print(ans if ans != INF else -1)\n \nmain()', 'def main():\n N, Ma, Mb = map(int, input().split())\n yakuhin = []\n for i in range(N):\n yakuhin.append(list(map(int, input().split())))\n \n INF = 10**15\n DP = [[[INF for _ in range(401)] for _ in range(401)] for _ in range(N+1)]\n DP[0][0][0] = 0\n \n for i in range(N):\n for j in range(401):\n for k in range(401):\n if(DP[i][j][k] != INF):\n DP[i+1][j][k] = min(DP[i+1][j][k], DP[i][j][k])\n DP[i+1][j+yakuhin[i][0]][k+yakuhin[i][1]] = min(DP[i+1][j+yakuhin[i][0]][k+yakuhin[i][1]], DP[i][j][k]+yakuhin[i][2])\n \n ans = INF\n for i in range(1, N+1):\n for j in range(1, 401):\n for k in range(1, 401):\n if(j*Mb == k*Ma):\n ans = min(ans, DP[i][j][k]) \n \n print(ans if ans != INF else -1)\n \nmain()'] | ['Wrong Answer', 'Accepted'] | ['s114853435', 's807931149'] | [23156.0, 60016.0] | [2105.0, 1779.0] | [994, 865] |
p03807 | u001687078 | 2,000 | 262,144 | There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard. | ['import sys\nsys.stdin.readline()\ncount = 0\na_list = list(map(int, sys.stdin.readline().split()))\nfor a in x_list:\n count += a%2\n\nprint("YES") if count%2==0 else print("NO")', 'import sys\ninput_ = sys.stdin.readline\ninput_()\nx_list = list(map(int, input_().split()))\nfor x in x_list:\n if x%2==0:\n a += 1\n\nif a%2==0:\n print("YES")\nelse:\n print("NO")', 'import sys\ninput()\ncount = 0\na_list = list(map(int, input().split()))\nfor a in a_list:\n count += a%2\n\nprint("YES") if count%2==0 else print("NO")'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s013588731', 's165841384', 's152566113'] | [14048.0, 14052.0, 14108.0] | [41.0, 42.0, 57.0] | [172, 177, 146] |
p03807 | u005569385 | 2,000 | 262,144 | There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard. | ['N = int(input())\na = list(map(int,input().split()))\ns = 0\nfor i in a:\n if i % 2 == 1:\n s += 1\nif s % 2 == 0:\n print("Yes")\nelse:\n print("No")', 'N = int(input())\na = list(map(int,input().split()))\ns = 0\nfor i in a:\n if i % 2 == 1:\n s += 1\nif s % 2 == 0:\n print("YES")\nelse:\n print("NO")'] | ['Wrong Answer', 'Accepted'] | ['s455923111', 's251191451'] | [20096.0, 20128.0] | [62.0, 60.0] | [157, 157] |
p03807 | u042802884 | 2,000 | 262,144 | There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard. | ["N=int(input())\nA=list(map(int,input().split()))\nB=[x for x in A if x%2==1]\nprint('Yes' if len(B)%2==0 else 'No')", "N=int(input())\nA=list(map(int,input().split()))\nB=[x for x in A if x%2==1]\nprint('YES' if len(B)%2==0 else 'NO')"] | ['Wrong Answer', 'Accepted'] | ['s829508431', 's133587755'] | [14112.0, 14108.0] | [51.0, 52.0] | [112, 112] |
p03807 | u064408584 | 2,000 | 262,144 | There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard. | ["n=int(input())\na=list(map(int, input().split()))\na=[i%2 for i in a]\nb=a.count(1)\nan=a.count(0)+b//2\nif an%2+b%2==1:print('YES')\nelse:print('NO')", "n=int(input())\na=list(map(int, input().split()))\na=[i%2 for i in a]\nb=a.count(1)\nanb,b=a.count(0)+b//2,b+b//2\nif an%2+b%2==1:print('YES')\nelse:print('NO')", "n=int(input())\na=list(map(int, input().split()))\na=[i%2 for i in a]\nb=a.count(1)\nanb,b=a.count(0)+b//2,b+b//2\nif an%2+b%2==1:print('YES')\nelse:print('NO')", "n=int(input())\na=list(map(int, input().split()))\na=[i for i in a if i%2==1]\nif len(a)%2==1:print('NO')\nelse:print('YES')"] | ['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s155122003', 's253040347', 's531189086', 's517573548'] | [14108.0, 14108.0, 14112.0, 14108.0] | [51.0, 51.0, 52.0, 51.0] | [144, 154, 154, 120] |
p03807 | u075012704 | 2,000 | 262,144 | There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard. | ['N = int(input())\nA = list(map(int, input().split()))\nodd = len(list(filter(lambda x: x % 2 == 1, A)))\nif odd % 2 == 0:\n print("Yes")\nelse:\n print("No")\n ', 'N = input()\nA = list(map(int, input().split()))\n\n\n\n\n\nodd = len(list(filter(lambda x: x % 2 == 1, A)))\nprint("YES" if odd % 2 == 0 else "NO")\n'] | ['Wrong Answer', 'Accepted'] | ['s692391360', 's669876314'] | [14108.0, 14112.0] | [56.0, 57.0] | [162, 339] |
p03807 | u095902316 | 2,000 | 262,144 | There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard. | ["numInput = int(input())\n\namount = numInput\nnumOdd = int(numInput / 2) + (numInput % 2)\nnumEven = int(numInput / 2)\n\nwhile True:\n\n if amount >= 3:\n if numOdd >= 2:\n numOdd -= 2\n numEven += 1\n amount -= 1\n else:\n numEven -= 1\n amount -= 1\n else:\n if amount == 2 and numOdd == 1 and numEven == 1:\n break\n if amount < 2:\n break\n\nif amount == 1:\n print('YES')\nelse:\n print('NO')\n", "numInput = int(input())\n\namount = numInput\nnumOdd = int(numInput / 2) + (numInput % 2)\nnumEven 0 int(numInput / 2)\n\nwhile True:\n\n if amount >= 2:\n if numOdd >= 2:\n numOdd -= 2\n numEven += 1\n amount -= 1\n else:\n numEven -= 1\n amount -= 1\n else:\n break\n\nif amount == 1:\n print('YES')\nelse:\n print('NO')\n", "numInput = int(input())\n\nnumSequence = list(map(int, input().split(' ')))\n\nnumOdd = 0\nfor i in range(0, len(numSequence)):\n if numSequence[i] % 2 == 1:\n numOdd += 1\n \nif numOdd % 2 == 0:\n print('YES')\nelse:\n print('NO')\n"] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s671067635', 's719446520', 's082866413'] | [3192.0, 3064.0, 14112.0] | [2102.0, 22.0, 77.0] | [491, 389, 243] |
p03807 | u107915058 | 2,000 | 262,144 | There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard. | ['N = int(input())\nA = list(map(int,input().split()))\nprint("Yes" if sum(A)%2==0 else "No")', 'N = int(input())\nA = list(map(int,input().split()))\nprint("YES" if sum(A)%2==0 else "NO")'] | ['Wrong Answer', 'Accepted'] | ['s794099510', 's381073530'] | [20008.0, 20132.0] | [52.0, 53.0] | [89, 89] |
p03807 | u117193815 | 2,000 | 262,144 | There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard. | ['n = int(input())\na = list(map(int, input().split()))\ne=0\no=0\nfor i in range(n):\n if a[i]%2==0:\n e+=1\n else:\n o+=1\nif o>e:\n if o%2!=0:\n print("No")\n else:\n print("Yes")\nelse:\n print("Yes")', 'n = int(input())\na = list(map(int, input().split()))\ne=0\no=0\nfor i in range(n):\n if a[i]%2==0:\n e+=1\n else:\n o+=1\nif n%2==0 and o%2==0:\n print("YES")\nelif n%2!=0 and o%2==0:\n print("YES")\nelse:\n print("NO")'] | ['Wrong Answer', 'Accepted'] | ['s281577965', 's378287590'] | [14104.0, 14108.0] | [64.0, 62.0] | [230, 235] |
p03807 | u125205981 | 2,000 | 262,144 | There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard. | ["def even(num):\n if num & 1:\n return('uneven')\n else:\n return('even')\n\nN = int(input())\nA = list(map(int, input().split()))\n\nn = 0\nfor a in A:\n if even(a) == 'uneven':\n n += 1\n\nif even(n) =a= 'even':\n print('YES')\nelse:\n print('NO')\n", "def even(num):\n if num & 1:\n return('uneven')\n else:\n return('even')\n\nN = int(input())\nA = list(map(int, input().split()))\n\nn = 0\nfor a in A:\n if even(a) == 'uneven':\n n += 1\n\nif even(n) == 'even':\n print('YES')\nelse:\n print('NO')\n"] | ['Runtime Error', 'Accepted'] | ['s378857792', 's341728544'] | [3192.0, 14364.0] | [22.0, 78.0] | [268, 267] |
p03807 | u126844573 | 2,000 | 262,144 | There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard. | ['a, b, c = sorted(list(map(int, input().split())))\n\ncount = (b - a) // 2\ncount += 2 if (a + count * 2) != b else 0\ncount += c - b\nprint(count)\n', 'input()\n\nprint("NO" if sum(map(int, input().split())) % 2 else "YES")\n'] | ['Runtime Error', 'Accepted'] | ['s571789569', 's693535190'] | [2940.0, 11104.0] | [18.0, 40.0] | [143, 70] |
p03807 | u128914900 | 2,000 | 262,144 | There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard. | ['n=int(input())\ns=input().split()\ni=0\ncount=0\nwhile i<0:\n if s[i]%2!=0:\n count+=1\nif count%2==0:\n print("Yes")\nelse:\n print("No")', 's=input().split()\ni=0\ncount=0\nwhile i<n:\n if int(s[i])%2!=0:\n count+=1\n i+=1\nif count%2==0:\n print("Yes")\nelse:\n print("No")', 'n=int(input())\ns=input().split()\ni=0\ncount=0\nwhile i<n:\n if int(s[i])%2!=0:\n count+=1\n i+=1\nif count%2==0:\n print("Yes")\nelse:\n print("No")', 'n=int(input())\ns=input().split()\ni=0\ncount=0\nwhile i<n:\n if int(s[i])%2!=0:\n count+=1\n i+=1\nif count%2==0:\n print("YES")\nelse:\n print("NO")'] | ['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s081385351', 's175320437', 's348528404', 's813005149'] | [11104.0, 3060.0, 11104.0, 11108.0] | [26.0, 17.0, 72.0, 72.0] | [134, 131, 146, 146] |
p03807 | u136395536 | 2,000 | 262,144 | There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard. | ['N = int(input())\nA = [int(i) for i in input().split()]\n\nodd = 0 \neven = 0 \n\nfor i in range(N):\n if A[i]%2 == 0:\n even += 1\n else:\n odd += 1\n\nif abs(odd - even)%2 == 0:\n print("YES")\nelif odd > even:\n print("NO")\nelse:\n print("YES")', 'N = int(input())\nA = [int(i) for i in input().split()]\n\nodd = 0\nfor i in range(N):\n if A[i]%2 != 0:\n odd += 1\n \nif odd%2 != 0:\n print("NO")\nelse:\n print("YES")'] | ['Wrong Answer', 'Accepted'] | ['s742899099', 's803541243'] | [14108.0, 14104.0] | [68.0, 62.0] | [274, 178] |
p03807 | u143492911 | 2,000 | 262,144 | There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard. | ['n=int(input())\na=list(map(int,input().split()))\neven_cnt=0\nodd_cnt=0\nfor i in a:\n if i%2==0:\n even_cnt+=1\n else:\n odd_cnt+=1\nif 1<=odd_cnt:\n even_cnt+=odd_cnt//2\u3000\n odd_cnt=odd_cnt%2 \n even_cnt=even_cnt%2\n if even_cnt==1 and odd_cnt==1:\n print("NO")\n else:\n print("YES")\nelse:\n print("YES")\n\n\n\n', 'n=int(input())\na=list(map(int,input().split()))\nood_cnt=0\nfor i in range(n):\n if a[i]%2==1:\n ood_cnt+=1\nif ood_cnt%2==0:\n print("YES")\nelse:\n print("NO")\n'] | ['Runtime Error', 'Accepted'] | ['s019522387', 's722373551'] | [3064.0, 14104.0] | [17.0, 59.0] | [479, 170] |
p03807 | u162612857 | 2,000 | 262,144 | There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard. | ["n = int(input())\nnums = list(map(int, input().split()))\n\nprint('NO' if (sum(map(lambda x:x%2, nums)))%2 else 'YESs')\n", "n = int(input())\nnums = list(map(int, input().split()))\n\nprint('NO' if (sum(map(lambda x:x%2, nums)))%2 else 'YES')\n"] | ['Wrong Answer', 'Accepted'] | ['s711877288', 's250742644'] | [14112.0, 14112.0] | [54.0, 55.0] | [117, 116] |
p03807 | u163320134 | 2,000 | 262,144 | There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard. | ["n=int(input())\narr=list(map(int,input().split()))\ncount=0\nfor i in range(n):\n if arr[0]%2==1:\n count+=1\nif count%2==1:\n print('NO')\nelse:\n print('YES')", "n=int(input())\narr=list(map(int,input().split()))\ncount=0\nfor i in range(n):\n if arr[i]%2==1:\n count+=1\nif count%2==1:\n print('NO')\nelse:\n print('YES')"] | ['Wrong Answer', 'Accepted'] | ['s593353321', 's054127821'] | [14108.0, 14108.0] | [61.0, 62.0] | [157, 157] |
p03807 | u178079174 | 2,000 | 262,144 | There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard. | ["A = list(map(int,input().split()))\nAA = sum([i%2 for i in A])\nif N == 1:\n print('YES')\n exit()\nif AA % 2 == 1:\n print('NO')\n exit()\nprint('YES') \n", "N = int(input())\nA = list(map(int,input().split()))\nAA = sum([i%2 for i in A])\nif N == 1:\n print('YES')\n exit()\nif AA % 2 == 1:\n print('NO')\n exit()\nprint('YES') \n"] | ['Runtime Error', 'Accepted'] | ['s312604107', 's512045357'] | [2940.0, 14108.0] | [17.0, 50.0] | [158, 175] |
p03807 | u185405877 | 2,000 | 262,144 | There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard. | ['n=int(input())\ni = list(map(int, input().split()))\ns=0\nfor j in range(len(i)):\n if i[j]%2==1:\n s+=1\nif s%2==0:\n print("Yes")\nelse:\n print("No")', 'n=int(input())\ni = list(map(int, input().split()))\ns=0\nfor j in range(n):\n if i[j]%2==1:\n s+=1\nif s%2==0:\n print("YES")\nelse:\n print("NO")'] | ['Wrong Answer', 'Accepted'] | ['s443001947', 's597764121'] | [14112.0, 14108.0] | [60.0, 60.0] | [149, 144] |
p03807 | u187109555 | 2,000 | 262,144 | There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard. | ['_ = input()\nAs = [int(x) for x in input().split()]\neven_pair_count = 0\nodd_pair_count = 0\neven_pair = []\nodd_pair = []\nfor a in As:\n if a%2 == 0:\n even_pair.append(1) \n if len(even_pair) == 2:\n even_pair = []\n even_pair_count += 1\n else:\n odd_pair.append(1)\n if len(odd_pair) == 2:\n odd_pair = []\n odd_pair_count += 1\n\n\npair_num = even_pair_count + odd_pair_count\nrest_num = len(even_pair) + len(odd_pair)\n\n# print(rest_num)\nelif rest_num == 2:\n print("NO")\nif pair_num == 1:\n print("YES")\nelif (pair_num+rest_num) % 2 == 0:\n print("YES")\nelse:\n print("NO")', '_ = input()\nAs = [int(x) for x in input().split()]\neven_pair_count = 0\nodd_pair_count = 0\neven_pair = []\nodd_pair = []\nfor a in As:\n if a%2 == 0:\n even_pair.append(1) \n if len(even_pair) == 2:\n even_pair = []\n even_pair_count += 1\n else:\n odd_pair.append(1)\n if len(odd_pair) == 2:\n odd_pair = []\n odd_pair_count += 1\n\npair_num = even_pair_count + odd_pair_count\nrest_num = len(even_pair) + len(odd_pair)\nif (pair_num+rest_num) % 2 == 0:\n print("Yes")\nelse:\n print("No")', '_ = input()\nAs = [int(x) for x in input().split()]\nif sum(As)%2 == 0:\n print("YES")\nelse:\n print("NO")'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s313397763', 's887935066', 's923566176'] | [3060.0, 14108.0, 14108.0] | [18.0, 81.0, 48.0] | [667, 557, 108] |
p03807 | u216962796 | 2,000 | 262,144 | There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard. | ["print(sum([1 if i % 2 == 1 else 0 for i in list(map(int, input().split(' ')))]))", "print(['NO', 'YES'][sum([1 if i % 2 == 1 else 0 for i in [int(input()) % 1] + list(map(int, input().split(' ')))]) % 2])", "print(sum([1 if i % 2 == 1 else 0 for i in [int(input()) % 1] + list(map(int, input().split(' ')))]))", "[print(['YES','NO'][len(list(filter(lambda x:x%2,map(int,input().split(' ')))))%2]) for _ in [input()]]"] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s138261530', 's265052673', 's355254605', 's109843704'] | [3188.0, 14108.0, 14112.0, 12132.0] | [19.0, 53.0, 51.0, 54.0] | [80, 120, 101, 103] |
p03807 | u223646582 | 2,000 | 262,144 | There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard. | ["N = int(input())\nA = [int(i) for i in input().split()]\n\nc = 0\nfor a in A:\n if a % 2 = 1:\n c += 1\nif c % 2 == 0:\n print('YES')\nelse:\n print('NO')\n", "N = int(input())\nA = [int(i) for i in input().split()]\n\nc = 0\nfor a in A:\n if a % 2 == 1:\n c += 1\nif c % 2 == 0:\n print('YES')\nelse:\n print('NO')\n"] | ['Runtime Error', 'Accepted'] | ['s432386761', 's793161816'] | [2940.0, 14108.0] | [17.0, 60.0] | [161, 162] |
p03807 | u240793404 | 2,000 | 262,144 | There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard. | ['n = int(input())\nl = list(map(int,input().split()))\nm = [i%2 for i in l]\nprint("YNeos"[l.count(1)%2==0::2])', 'n = int(input())\nl = list(map(int,input().split()))\nm = [i%2 for i in l]\nprint("YNEOS"[m.count(1)%2==1::2])'] | ['Wrong Answer', 'Accepted'] | ['s776420190', 's637557219'] | [14108.0, 14108.0] | [52.0, 60.0] | [107, 107] |
p03807 | u242031676 | 2,000 | 262,144 | There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard. | ['n,*a=map(int,open(0).read().split());print("YNeos"[sum(map(lambda x:x%2, a))%2::2])', 'n,*a=map(int,open(0).read().split());print("YNEOS"[sum(map(lambda x:x%2, a))%2::2])'] | ['Wrong Answer', 'Accepted'] | ['s983943871', 's098802452'] | [14060.0, 14188.0] | [56.0, 53.0] | [83, 83] |
p03807 | u252828980 | 2,000 | 262,144 | There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard. | ['n = int(input())\nL = list(map(int,input().split()))\ncnt = 0\nfor i in range(n):\n if L[i]%2 == 1:\n cnt += 1\nif cnt%2 == 1:\n print("YES")\nelse:\n print("NO")', 'n = int(input())\nL = list(map(int,input().split()))\ncnt = 0\nfor i in range(n):\n if L[i]%2 == 1:\n cnt += 1\nif cnt%2 == 1:\n print("NO")\nelse:\n print("YES")'] | ['Wrong Answer', 'Accepted'] | ['s489964951', 's878037909'] | [14108.0, 14112.0] | [60.0, 61.0] | [159, 159] |
p03807 | u271456715 | 2,000 | 262,144 | There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard. | ["n = int(input().strip())\na = [int(x) for x in input().strip().split()]\nflg = [-1 for i in range(n)]\nb = []\nl = [[] for i in range(n)]\nfor i in range(n - 1):\n b.append([int(x) - 1 for x in input().strip().split()])\nfor x in b:\n l[x[0]].append(x[1])\n l[x[1]].append(x[0])\n \nwhile True:\n minimum = a[0]\n idx = []\n for i, x in enumerate(a):\n if flg[i] != -1 or x > minimum:\n continue\n if x < minimum:\n minimum = x\n idx =[i]\n else:\n idx.append(i)\n while True:\n w = []\n for i in idx:\n flg[i] = 0\n for x in l[i]:\n if flg[x] == -1 and a[x] != a[i]:\n flg[x] = 1\n w.append(x)\n idx = []\n for i in w:\n for x in l[i]:\n if flg[x] == -1:\n flg[x] = 0\n for y in l[x]:\n if flg[y] == -1 and a[x] > a[y]:\n flg[x] = -1\n break\n if flg[x] == 0:\n idx.append(x)\n if len(idx) == 0:\n break\n if -1 not in flg:\n break\n\nsep = ''\ns = ''\nfor i, x in enumerate(flg):\n if x == 1:\n s += sep + str(i + 1)\n sep = ' '\n\nprint(s)\n", "input()\ni = [int(x) % 2 for x in input().strip().split()]\nif sum(i) % 2 == 0:\n print('YES')\nelse:\n print('NO')"] | ['Runtime Error', 'Accepted'] | ['s210159326', 's224251881'] | [14884.0, 11104.0] | [69.0, 51.0] | [1079, 112] |
p03807 | u315485238 | 2,000 | 262,144 | There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard. | ["N = int(input())\nA = list(map(int, input().split()))\nodd = [a for a in A if a%2]\n\nif odd%2:\n print('NO')\nelse:\n print('YES')", "N = int(input())\nA = list(map(int, input().split()))\nodd = [a for a in A if a%2]\n\nif len(odd)%2:\n print('NO')\nelse:\n print('YES')"] | ['Runtime Error', 'Accepted'] | ['s740493431', 's386522638'] | [14108.0, 14108.0] | [50.0, 49.0] | [126, 131] |
p03807 | u319737087 | 2,000 | 262,144 | There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard. | ["n = int(input())\narg_list = int(input())\n\nk = 0\nfor item in arg_list:\n if item % 2 == 1 :\n k +=1\nif k == 1:\n print('YES')\nelse:\n print('NO')\n ", 'n = int(input())\na = map(int, input().split())\ncount = 0\nfor i in a:\n if i % 2 == 1:\n count += 1\nprint("YES" if count % 2 == 0 else "NO")\n'] | ['Runtime Error', 'Accepted'] | ['s738014195', 's392056127'] | [5032.0, 11108.0] | [32.0, 73.0] | [165, 148] |
p03807 | u328207927 | 2,000 | 262,144 | There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard. | ["n=int(input())\na=[int(i) for i in input().split()]\ng=[]\nk=[]\nfor i in a:\n if i%2==0:\n g+=[i]\n g=[sum(g)]\n else:\n k+=[i]\n if len(k)%2==0:\n g+=[sum(k)]\n k=[]\n print(g,k)\nprint('YES'if g==[] or k==[] else 'NO')", "n=int(input())\na=[int(i) for i in input().split()]\ng=[]\nk=[]\nfor i in a:\n if i%2==0:\n g+=[i]\n g=[sum(g)]\n else:\n k+=[i]\n if len(k)%2==0:\n g+=[sum(k)]\n k=[]\n\nprint('YES'if g==[] or k==[] else 'NO')"] | ['Wrong Answer', 'Accepted'] | ['s722893128', 's526140694'] | [14108.0, 14108.0] | [308.0, 106.0] | [266, 252] |
p03807 | u328510800 | 2,000 | 262,144 | There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard. | ['input()\na = list(map(int, input().split()))\nl = len(filter(lambda x : x & 1, a))\nif l & 1:\n print("NO")\nelse:\n print("YES")', 'input()\na = list(map(int, input().split()))\nl = len(list(filter(lambda x : x & 1, a)))\nif l & 1:\n print("NO")\nelse:\n print("YES")'] | ['Runtime Error', 'Accepted'] | ['s465141546', 's701026469'] | [14112.0, 14104.0] | [43.0, 54.0] | [125, 131] |
p03807 | u329400445 | 2,000 | 262,144 | There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard. | ['import numpy as np\n\nN = int(input())\na = input().split(" ")\nA = [int(i) for i in a]\n\nk = [1 if A[i]%2==1 else 0 for i in range(N)]\n\nif sum(k)%2 == 0:\n print("Yes")\nelse:\n print("No")', 'import numpy as np\n\nN = int(input())\na = input().split(" ")\nA = [int(i) for i in a]\nprint(A)\nk = [1 if A[i]%2==1 else 0 for i in range(N)]\n\nif sum(k)%2 == 0:\n print("YES")\nelse:\n print("NO")', 'import numpy as np\n\nN = int(input())\na = input().split(" ")\nA = [int(i) for i in a]\n\nk = [1 if A[i]%2==1 else 0 for i in range(N)]\n\nif sum(k)%2 == 0:\n print("YES")\nelse:\n print("NO")'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s342591268', 's522744177', 's220055123'] | [23852.0, 27176.0, 23852.0] | [192.0, 203.0, 194.0] | [188, 196, 188] |
p03807 | u339199690 | 2,000 | 262,144 | There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. * Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j. Determine whether it is possible to have only one integer on the blackboard. | ['N = int(input())\nA = list(map(int, input().split()))\n\neven_count = 0\nodd_count = 0\nfor a in A:\n if a % 2 == 0:\n even_count += 1\n else:\n odd_count += 1\n\nif odd_count % 2 == 1:\n print("No")\nelse:\n print("Yes")\n', 'N = int(input())\nA = list(map(int, input().split()))\n\nodd_count = 0\nfor a in A:\n if a % 2 == 1:\n odd_count += 1\n\nif odd_count % 2 == 0:\n print("Yes")\nelse:\n print("No")\n', 'N = int(input())\nA = list(map(int, input().split()))\n\neven_count = 0\nodd_count = 0\nfor a in A:\n if a % 2 == 0:\n even_count += 1\n else:\n odd_count += 1\n\nif odd_count % 2 == 1:\n if even_count == 0 and odd_count == 1:\n print("Yes")\n exit()\n print("No")\nelse:\n print("Yes")', 'N = int(input())\nA = list(map(int, input().split()))\n\nodd = 0\n\nfor a in A:\n if a % 2 == 1:\n odd += 1\n\nif odd % 2 == 1:\n print("NO")\nelse:\n print("YES")\n'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s562204809', 's680624692', 's834026302', 's037097727'] | [14108.0, 14112.0, 14112.0, 14112.0] | [58.0, 54.0, 58.0, 56.0] | [234, 185, 312, 168] |