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 |
|---|---|---|---|---|---|---|---|---|---|---|
p02732 | u814271993 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['rom collections import Counter\nN=int(input())\nA=list(map(int, input().split()))\n \ncount = Counter(A)\nvals = count.values()\nsum_ = 0\nfor v in vals:\n if v >= 2: sum_ += v*(v-1)\nsum_ //= 2\n \nfor k in range(N):\n if count[A[k]] < 2: print(sum_)\n else:print(sum_ + 1 - count[A[k]])', 'import numpy as np\nn = int(input())\na = list(map(int,input().split()))\ns = np.zeros(n+1)\nfor i in a:\n s[i]+=1\nal = sum((s*(s-1))/2)\nfor i in range(n):\n ans=al-(s[a[i]]-1)\n print(int(ans))'] | ['Runtime Error', 'Accepted'] | ['s385071674', 's227520008'] | [8948.0, 51424.0] | [26.0, 459.0] | [278, 196] |
p02732 | u814885356 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['import collections\n\n# input\nN = int(input())\nA = map(int,input().split())\n# calculatioin\ncnt = collections.Counter(A)\nfull_cnt = int(sum(cnt[key]*(cnt[key]-1)/2 for key in cnt))\nfor i in range(N):\n print(full_cnt - cnt[A[i]]+1)', 'import collections\n\n# input\nN = int(input())\nA = input().split()\n# calculatioin\ncnt = collections.Counter(A)\nfull_cnt = int(sum(cnt[key]*(cnt[key]-1)/2 for key in cnt))\nfor i in range(N):\n print(full_cnt - cnt[A[i]]+1)'] | ['Runtime Error', 'Accepted'] | ['s165727892', 's152732130'] | [29472.0, 26784.0] | [151.0, 368.0] | [228, 219] |
p02732 | u819593641 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['from math import factorial\n\nN = int(input())\nAn = list(map(int, input().split()))\n\ndef combination(n,r):\n if n < 2:\n return 0\n else:\n print(factorial(n) / factorial(r) / factorial(n-r) )\n return factorial(n) / factorial(r) / factorial(n-r)\n\nlens = []\nans = 0\nfor p in range(N):\n lens.append(An.count(p))\nfor p in range(N):\n lend = lens.copy()\n if lend[p] == 0:\n continue\n else:\n lend[p] -= 1\n for k in range(N):\n ans += combination(lend[k], 2)\n\nprint(int(ans))', 'from math import factorial\n\nN = int(input())\nAn = list(map(int, input().split()))\n\ndef combination(n,r):\n if n < 2:\n return 0\n else:\n return factorial(n) / factorial(r) / factorial(n-r)\n\nlens = []\nans = 0\nfor p in range(N):\n lens.append(An.count(p))\nfor p in range(N):\n lend = lens.copy()\n if lend[p] == 0:\n continue\n else:\n lend[p] -= 1\n for k in range(N):\n ans += combination(lend[k], 2)\n\nprint(int(ans))\n', 'N = int(input())\nAn = list(map(int,input().split()))\n\n# n(n-1)/2 - (n-1)(n-2)/2 = n-1\ndic = {}\nsu = 0\nm = 0\nfor a in An:\n dic[a] = 0\nfor a in An:\n dic[a] += 1 \nfor d,i in enumerate(dic):\n su += dic[i] * (dic[i]-1) / 2\nfor a in An:\n print(int(su - dic[a] + 1))\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s648617154', 's705818551', 's048230697'] | [26140.0, 26140.0, 25644.0] | [2108.0, 2105.0, 410.0] | [485, 429, 264] |
p02732 | u830054172 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['from collections import Counter\nimport math\n\ndef combinations_count(n, r):\n return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))\n\nN = int(input())\na = list(map(int, input().split()))\n\na_cnt = Counter(a)\n\na_comb = {}\nfor key, val in a_cnt.items():\n if val >= 2:\n a_comb[key] = combinations_count(val, 2)\n else:\n a_comb[key] = 0\nprint(a_cnt)\nprint(a_comb)\n\nfor num in a:\n dic = a_comb.copy()\n if dic[num] <= 1:\n dic[num] = 0\n else: \n dic[num] = combinations_count(a_cnt[num]-1, 2)\n print(int(sum(dic.values())))', 'from collections import Counter\nimport math\n\ndef combinations_count(n, r):\n return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))\n\nN = int(input())\na = list(map(int, input().split()))\n\na_cnt = Counter(a)\n\na_comb = {}\nfor key, val in a_cnt.items():\n if val >= 2:\n a_comb[key] = combinations_count(val, 2)\n else:\n a_comb[key] = 0\n\nsum_v = sum(a_comb.values())\n\nfor num in a:\n print(sum_v-a_cnt[num]+1)'] | ['Wrong Answer', 'Accepted'] | ['s598461316', 's940076066'] | [44140.0, 32276.0] | [2105.0, 1688.0] | [577, 443] |
p02732 | u830588156 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['import collections\nN = int(input())\nA = list(map(int,input().split()))\nCA = collections.Counter(A)\nS = 0\nfor i in CA.values():\n S += i*(i-1)//2\nfor x in range(A):\n print(S - count[x] + 1)', 'import collections\nN = int(input())\nA = list(map(int,input().split()))\nCA = collections.Counter(A)\nS = 0\nfor i in CA.values():\n S += i*(i-1)//2\nfor x in A:\n print(S - count[x] + 1)', 'import collections\nN = int(input())\nA = list(map(int,input().split()))\nCA = collections.Counter(A)\nS = 0\nfor i in CA.values():\n S += i*(i-1)/2\nfor k in range(N):\n print(S - A.count(A[k]) + 1)', 'import collections\nN = int(input())\nA = list(map(int,input().split()))\nCA = collections.Counter(A)\nS = 0\nfor i in CA.values():\n S += i*(i-1)//2\nfor x in range(A):\n print(S - A.count(x) + 1)', 'import collections\nN = int(input())\nA = list(map(int,input().split()))\nCA = collections.Counter(A)\nS = 0\nfor i in CA.values():\n S += i*(i-1)/2\nfor x in range(A):\n print(S - A.count(x) + 1)', 'import collections\nN = int(input())\nA = list(map(int,input().split()))\nCA = collections.Counter(A)\nS = 0\nfor i in range(CA.values()):\n S += int(i*(i-1)/2)\nfor k in range(N):\n print(S - A.count(A[k]) + 1)', 'N = int(input())\nA = list(map(int,input().split()))\nS = 0\nfor i in range(N):\n S += int(A[i]*(A[i]-1)/2)\nfor k in range(N):\n print(S - A.count(A[k]) + 1)', 'import collections\nN = int(input())\nA = list(map(int,input().split()))\nCA = collections.Counter(A)\nS = 0\nfor i in CA.values():\n S += i*(i-1)//2\nfor x in A:\n print(S - CA[x] + 1)'] | ['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s134453805', 's441374274', 's499721043', 's573004074', 's855881940', 's891593052', 's940331089', 's248145708'] | [26780.0, 26780.0, 26780.0, 26780.0, 26780.0, 26780.0, 26140.0, 26780.0] | [126.0, 120.0, 2104.0, 123.0, 116.0, 102.0, 2104.0, 350.0] | [193, 186, 197, 195, 194, 209, 158, 183] |
p02732 | u830881690 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['N = int(input())\nN = list(range(1,N+1))\nA = list(map(int, input().split())\n\nfor k in range(1, N+1):\n A = A.remove(A[k])\n ans = 0\n for i in range(1,N+1):\n \tn = sum(A[j] == i for j in range(1,N))\n \tnc2 = n * (n-1) / 2\n \tans += nc2\n \n print(ans)', 'N = int(input())\nA = list(map(int, input().split()))\n\nfor k in range(N):\n del A[k]\n ans = 0\n \n for i in range(1,N+1):\n n = A.count(i)\n nc2 = n * (n-1) / 2\n ans += nc2\n print(ans)', 'N = int(input())\nA = list(map(int, input().split())\n\nfor k in range(N):\n del A[k]\n ans = 0\n for i in range(1,N+1):\n \tn = sum(A[j] == i for j in range(1,N))\n \tnc2 = n * (n-1) / 2\n \tans += nc2\n \n print(ans)', 'N = int(input())\nA = list(map(int, input().split())\n\nfor k in range(1, N+1):\n A = A.remove(k)\n ans = 0\n for i in range(1,N+1):\n \tn = sum(A[j] == i for j in range(1,N))\n \tnc2 = n * (n-1) / 2\n \tans += nc2\n \n print(ans)', 'N = int(input())\nA = list(map(int, input().split()))\n\nfor k in range(N):\n del A[k]\n ans = 0\n \n for i in range(1,N+1):\n n = sum(A[j] == i for j in range(N-1))\n nc2 = n * (n-1) / 2\n ans += nc2\n print(ans)', 'N = int(input())\nA = list(map(int, input().split()))\nB = [0] * (N+1)\n\nfor i in A:\n B[i] += 1\nsum_original = sum([j*(j-1)//2 for j in B])\nfor k in range(N):\n print(sum_original - B[A[k]] + 1)'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s189945206', 's333116553', 's429448655', 's565261591', 's826318579', 's429391340'] | [2940.0, 26268.0, 2940.0, 2940.0, 24748.0, 26140.0] | [17.0, 2104.0, 17.0, 18.0, 2104.0, 278.0] | [306, 214, 268, 280, 238, 196] |
p02732 | u833738197 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['n = int(input())\na_l = list(map(int, input().split()))\n\ncnt = [0 for i in range(n)]\n\nfor i in range(n):\n cnt[a_l[i]]+=1\nans = 0\n\nfor a in cnt:\n ans += a*(a-1)/2\nfor i in range(n):\n print(ans - (cnt[a_l[i]]-1))', 'n = int(input())\nA = list(map(int,input().split()))\n\nfrom collections import Counter\ncount = Counter(A)\n \ns = 0\nfor c in list(count.values()):\n s += c*(c-1)/2\n\nans = 0\nfor a in A:\n n = count[a]\n ans = s - n*(n-1)/2 + (n-1)*(n-2)/2\n print(int(ans))'] | ['Runtime Error', 'Accepted'] | ['s306092647', 's462468783'] | [26012.0, 32228.0] | [395.0, 265.0] | [218, 259] |
p02732 | u840974625 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['n = int(input())\nl = list(map(int, input().split()))\n\nans = 0\n\nk = [0 for _ in range(n+1)]\n\nfor i in range(n):\n k[l[i]] += 1\n \nll = len(k)\nfor i in range(ll):\n a = k[i]\n if a <= 1:\n pass\n else:\n ans += (a * (a - 1))/2\n \nfor i in range(n):\n a = k[l[i]]\n b = (a * (a - 1))/2\n c = a - 1\n if c <= 1:\n print(ans)\n else:\n pans = ans - b\n c = (c * (c - 1))/2\n pans = pans + c\n print(pans)', 'n = int(input())\nl = list(map(int, input().split()))\n\nans = 0\n\nk = [0 for _ in range(n+1)]\n\nfor i in range(n):\n k[l[i]] += 1\n \nll = len(k)\nfor i in range(ll):\n a = k[i]\n if a <= 1:\n pass\n else:\n ans += (a * (a - 1))/2\n \nfor i in range(n):\n a = k[l[i]]\n b = (a * (a - 1))/2\n c = a - 1\n if c <= 1:\n print(int(ans))\n else:\n pans = ans - b\n c = (c * (c - 1))/2\n pans = pans + c\n print(int(pans))', 'n = int(input())\nl = list(map(int, input().split()))\n\nans = 0\n\nk = [0 for _ in range(n+1)]\n\nfor i in range(n):\n k[l[i]] += 1\n \nll = len(k)\nfor i in range(ll):\n a = k[i]\n if a <= 1:\n pass\n else:\n ans += (a * (a - 1))/2\n \nfor i in range(n):\n a = k[l[i]]\n b = (a * (a - 1))/2\n c = a - 1\n if a < 1:\n print(int(ans))\n else:\n pans = ans - b\n c = (c * (c - 1))/2\n pans = pans + c\n print(int(pans))'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s812569246', 's920983162', 's754793767'] | [26140.0, 26140.0, 26140.0] | [486.0, 445.0, 456.0] | [467, 477, 476] |
p02732 | u845536647 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['from collections import Counter\nN = int(input())\nB = [int(x) for x in input().split()]\nA=Counter(B)\nV, C = zip(*A.most_common())\ncount=0\nfor x in C:\n if x==0:\n break\n count+=x*(x-1)/2\nfor x in A:\n ans=count-C[V.index(x)]+1\n print(int(ans))', 'from collections import Counter\nN = int(input())\nB = [int(x) for x in input().split()]\nA=Counter(B)\nV, C = zip(*A.most_common())\ncount=0\ni=0\ndict={}\nfor x in C:\n count+=x*(x-1)/2\n dict[V[i]]=x\n i+=1\nfor x in B:\n ans=count-dict[x]+1\n print(int(ans))'] | ['Wrong Answer', 'Accepted'] | ['s042617981', 's077231738'] | [36488.0, 37024.0] | [2105.0, 514.0] | [246, 253] |
p02732 | u851035514 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['from operator import mul\nfrom functools import reduce\nimport numpy as np\n\ndef cmb(n,r):\n r = min(n-r,r)\n if r == 0: return 1\n over = reduce(mul, range(n, n - r, -1))\n under = reduce(mul, range(1,r + 1))\n return over // under\n\nN = int(input())\nA = list(map(int, input().split()))\nB = A[:]\nB.sort()\nC = [B[0]]\nD = [1]\nL = 0\nfor i in range(N-1):\n if B[i] == B[i+1]:\n D[L] += 1\n else:\n C.append(B[i+1])\n D.append(1)\n L += 1\nM = len(C)\nD1 = D[:]\nfor i in range(M):\n if D[i] > 1:\n D[i] = cmb(D[i],2)\n else:\n D[i] = 0\nfor i in range(M):\n if D1[i] > 2:\n D1[i] = cmb(D1[i]-1,2)\n else:\n D1[i] = 0\n\nD = np.array(D)\nD1 = np.array(D1)\nE = []\nE.append(D1[0]+np.sum(D[1:]))\nfor i in range(1,M-1):\n E.append(D1[i] + np.sum(D[0:i]) + np.sum(D[i+1:M]))\nE.append(D1[M-1] + np.sum(D[:M-1]))\nfor i in range(N):\n print(E[C.index(A[i])])\nprint(E)', 'N = int(input())\nA = list(map(int, input().split()))\nC = {}\nfor i in A:\n if i in C.keys():\n C[i] += 1\n else:\n C[i] = 1\n\ntotal = 0\n\nfor i in C.keys():\n if C[i]>1:\n total += (C[i]*(C[i]-1))//2\n\nfor i in A:\n print(total-(C[i]-1))\n'] | ['Wrong Answer', 'Accepted'] | ['s507363464', 's781015106'] | [34108.0, 24748.0] | [2109.0, 315.0] | [918, 259] |
p02732 | u851319680 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['import collections\n_=int(input())\nl = list(map(int, input().split()))\nc = collections.Counter(l)\nM={}\n\nfor i,v in c.items():\n if v>1:\n M[i] = v*(v-1)/2\n\nfor k in l:\n M_ = M.copy()\n M_[k] = M_[k]*(c[k]-2)/c[k]\n print(sum(M_.values()))', 'import collections\n_ = int(input())\nl = list(map(int, input().split()))\nc = collections.Counter(l)\nM=0\nfor v in c.values():\n if v>1:\n M += v*(v-1)/2\n\nfor k in l:\n print(int(M-c[k]+1))\n'] | ['Runtime Error', 'Accepted'] | ['s624301848', 's900222376'] | [30996.0, 26908.0] | [619.0, 376.0] | [254, 198] |
p02732 | u857547702 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['import copy\n\n# N=In[0][0]\n# A=In[1]\nN=int(input())\nI=list(map(int,input().split()))\nfor j in range(N):\n counter=[0 for i in range(N+1)]\n A=copy.deepcopy(I)\n A.pop(j)\n B=[]\n for i in A:\n counter[i]+=1\n for i in counter:\n if i>1:\n B.append(f(i)/(f(2)*f(i-2)))\n print(int(sum(B)))', 'import copy\n\n# N=In[0][0]\n# A=In[1]\nN=int(input())\nA=list(map(int,input().split()))\ncounter=[0 for i in range(N+1)]\nans2=[0 for i in range(N+1)]\nB=[]\nfor i in A:\n counter[i]+=1\nans=[0 for i in range(N+1)]\nfor i,value in enumerate(counter):\n if value>0:\n ans[i]=(value*(value-1)//2)\n ans2[i]=((value-1)*(value-2)//2)\ntotal=sum(ans)\nfor i in A:\n temp=total\n temp-=ans[i]\n temp+=ans2[i]\n print(temp)\n'] | ['Runtime Error', 'Accepted'] | ['s956147833', 's543264396'] | [26908.0, 27036.0] | [248.0, 392.0] | [381, 487] |
p02732 | u859987056 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['def cmb(n):\n if n < 2:\n return 0\n else:\n return (n*(n-1)/2)\n\nN = int(input())\nA = list(map(int,input().split()))\n\nnum_dict = {i:0 for i in range(1,N+1)}\nfor i in range(N):\n num_dict[A[i]] += 1\n\nS = 0\nfor i in range(1,N+1):\n S += cmb(num_dict[i])\n\nfor i in range(N):\n tmp = 0\n S_dif = cmb(num_dict[A[i]]-1) - cmb(num_dict[A[i]])\n tmp = S + S_dif\n print(tmp)', 'def cmb(n):\n if n < 2:\n return 0\n else:\n return (n*(n-1)/2)\n\nN = int(input())\nA = list(map(int,input().split()))\n\nnum_dict = {i:0 for i in range(1,N+1)}\nfor i in range(N):\n num_dict[A[i]] += 1\n\nS = 0\nfor i in range(1,N+1):\n S += cmb(num_dict[i])\n\nfor i in range(N):\n tmp = 0\n S_dif = cmb(num_dict[A[i]]-1) - cmb(num_dict[A[i]])\n tmp = S + S_dif\n print(int(tmp))'] | ['Wrong Answer', 'Accepted'] | ['s597450669', 's487271511'] | [40924.0, 40908.0] | [421.0, 414.0] | [394, 399] |
p02732 | u865119809 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['from collections import Counter\ndef cmb(n):\n if n < 2:\n return 0\n else:\n return (n * (n-1)) // 2\n\nn = int(input())\nls = list(map(int,input().split()))\n\ncs = Counter(a)\ns = 0\n\nfor v in cs.values():\n s += cmb(v)\n\nfor a in ls:\n print(s - cmb(c[a]) + cmb(c[a] - 1))', 'from collections import Counter\n\ndef cmb(n):\n if n < 2:\n return 0\n else:\n return n * (n-1) / 2\n\nn = int(input())\nls = list(map(int,input().split()))\n\ncs = Counter(a)\ns = 0\n\nfor v in cs.values():\n s += cmb(v)\n\nfor a in ls:\n print(s - cmb(c[a]) + cmb(c[a] - 1))', 'from collections import Counter\ndef cmb(n):\n if n < 2:\n return 0\n else:\n return (n * (n-1)) // 2\n\nn = int(input())\nls = list(map(int,input().split()))\n\ncs = Counter(a)\ns = 0\n\nfor v in cs.values():\n s += cmb(v)\n\nfor a in ls:\n print(s - cmb(cs[a]) + cmb(cs[a] - 1))', 'from collections import Counter\ndef cmb(n):\n if n < 2:\n return 0\n else:\n return (n * (n-1)) // 2\n\nn = int(input())\nls = list(map(int,input().split()))\n\ncs = Counter(ls)\ns = 0\n\nfor v in cs.values():\n s += cmb(v)\n\nfor a in ls:\n print(s - cmb(cs[a]) + cmb(cs[a] - 1))'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s317373472', 's434004022', 's812900929', 's618102832'] | [27164.0, 27164.0, 27292.0, 26908.0] | [144.0, 125.0, 118.0, 482.0] | [287, 285, 289, 290] |
p02732 | u865383026 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['N = int(input())\nA = list(map(int,input().split()))\nB = [A.count(i) for i in range (N + 1)]\nprint(B)\nC = 0\nfor i in range(N + 1):\n C += int(B[i] * (B[i] - 1) / 2)\nfor j in A:\n print(0 if B[j] < 2 else C + 1 - B[j])', 'N = int(input())\nA = list(map(int,input().split()))', 'N = int(input())\nA = (input().split())\nB = []\nC = 0\nfor i in range(N + 1):\n B.append(A.count(str(i)))\n C += int(B[i] * (B[i] - 1) / 2)\nprint(B)\nfor j in range(N):\n if B[int(A[j])] > 1:\n D = C + 1 - B[int(A[j])]\n print(D)\n else:\n print(0)', 'N = int(input())\nA = list(int(x) for x in input().split())', 'import collections\nN = int(input())\nA = list(map(int, input().split()))\nB = collections.Counter(A)\nL = {key:(B[key] * (B[key] - 1) // 2) for key in B}\ntotal = sum(L.values())\n#print(f"A = {A}\\nB = {B}\\nL = {L}\\ntotal = {total}")\n[print(total if L[i] == 0 else total - L[i] + ((B[i] - 1) * (B[i] - 2) // 2)) for i in A]'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s070569766', 's307637025', 's464505942', 's881528935', 's972299505'] | [26012.0, 26268.0, 19040.0, 24996.0, 32028.0] | [2104.0, 69.0, 2105.0, 78.0, 400.0] | [216, 51, 250, 58, 318] |
p02732 | u865413330 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['from math import factorial\n\nN = int(input())\nnums = list(map(int, input().split()))\nd = dict()\n\nfor num in nums:\n if num not in d:\n d[num] = 1\n else:\n d[num] += 1\n\ntotal = 0\nfor i in d:\n n = d[i]\n if n == 2:\n total += 1\n elif n > 2:\n total += factorial(n) / factorial(2) / factorial(n - 2)\n\nfor num in nums:\n tmp = d[num] - 1\n# if tmp >= 2:\n# hoge = factorial(tmp) / factorial(2) / factorial(tmp - 2)\n print(total - tmp)\n', 'import math\n\nN = int(input())\nnums = list(map(int, input().split()))\nnumsB = nums[:]\nd = dict()\n\ndef combinations_count(n, r):\n return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))\n\nfor num in nums:\n if num not in d:\n d[num] = 1\n else:\n d[num] += 1\n\ntotal = 0\nfor i in d:\n n = d[i]\n if n == 2:\n total += 1\n elif n > 2:\n total += combinations_count(n, 2)\n\nfor num in numsB:\n tmp = d[num] - 1\n# if tmp >= 2:\n# hoge = factorial(tmp) / factorial(2) / factorial(tmp - 2)\n print(int(total - tmp))\n'] | ['Runtime Error', 'Accepted'] | ['s027438362', 's997348545'] | [26140.0, 26140.0] | [822.0, 1724.0] | [480, 572] |
p02732 | u867826040 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['import collections\nfrom scipy.misc import comb\nn = int(input())\na = list(map(int,input().split()))\nfor i in range(len(a)):\n o = 0\n b = a[:]\n del b[i]\n c = collections.Counter(b)\n n = len(set(b))\n for i in c.values():\n o += comb(i,2,exact=True)\n print(o)\n ', 'from collections import Counter\ndef comb(x):\n return x*(x-1)//2\nn = int(input())\na = list(map(int,input().split()))\nc = Counter(a)\nb = 0\nfor i in c.values():\n b+=comb(i)\nfor k in range(n):\n print(b-c[a[k]]+1)'] | ['Time Limit Exceeded', 'Accepted'] | ['s024989909', 's277943814'] | [46392.0, 25896.0] | [2112.0, 360.0] | [266, 217] |
p02732 | u868628468 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['n = int(input())\na = []\nd = {}\nans = 0\nfor _ in range(n):\n a.append(int(input()))\nfor i in a:\n d[i] = d.get(i,0) + 1\nfor key in d:\n ans += d[key]*(d[key]-1)//2\nfor i in a:\n print(ans + 1 - d[i])', 'n = int(input())\na = list(map(int,input().split()))\nd = {}\nans = 0\nfor i in a:\n d[i] = d.get(i,0) + 1\nfor key in d:\n ans += d[key]*(d[key]-1)//2\nfor i in a:\n print(ans + 1 - d[i])'] | ['Runtime Error', 'Accepted'] | ['s209467811', 's823880915'] | [6492.0, 26268.0] | [25.0, 370.0] | [206, 188] |
p02732 | u870575557 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ["def main():\n import math\n import collections\n N = int(input())\n A = list(map(int, input().split()))\n tt = 0\n \n ann = 0\n\n def comb(m, n):\n #return math.factorial(m) // (math.factorial(n) * math.factorial(m - n))\n return ((m - 1 + 1) / 1) * (m - 2 + 1) / 2\n\n \n\n C = collections.Counter(A)\n for i in C.values():\n if i>=2:\n tt = tt + comb(i, 2)\n\n for i in A:\n f = C[i] #A_count(A[i])\n if f>=3:\n ann = (tt - comb(f, 2) + comb(f-1, 2))\n elif f==2:\n ann = tt - comb(f, 2)\n else:\n ann = tt\n print(ann)\n\n \n # print(i)\n\n\nif __name__ == '__main__':\n main()", "def main():\n import math\n import collections\n N = int(input())\n A = list(map(int, input().split()))\n tt = 0\n \n ann = 0\n\n def comb(m, n):\n #return math.factorial(m) // (math.factorial(n) * math.factorial(m - n))\n return ((m - 1 + 1) / 1) * (m - 2 + 1) / 2\n\n \n\n C = collections.Counter(A)\n for i in C.values():\n if i>=2:\n tt = tt + comb(i, 2)\n\n for i in A:\n f = C[i] #A_count(A[i])\n if f>=3:\n ann = (tt - comb(f, 2) + comb(f-1, 2))\n elif f==2:\n ann = tt - comb(f, 2)\n else:\n ann = tt\n print(int(ann))\n\n \n # print(i)\n\n\nif __name__ == '__main__':\n main()"] | ['Wrong Answer', 'Accepted'] | ['s179694421', 's131016728'] | [26780.0, 26780.0] | [567.0, 536.0] | [869, 874] |
p02732 | u878654696 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['n = int(input())\na = list(map(int, input().split()))\n\nb = set(a)\n\nc = {}\n\nfor i in a:\n c[i] = c.get(i, 0) + 1\n\nd = {}\n\nfor k in a:\n if d.get(k, "hello") == "hello":\n ans = 0\n for i in b:\n if i != k:\n ans += c[i]*(c[i]-1)//2\n else:\n ans += (c[i]-1)*(c[i]-2)//2\n d[k] = ans\n else:\n ans = d[ans]\n print(ans)\n', 'n = int(input())\na = list(map(int, input().split()))\n\nc = {}\n\nfor i in a:\n c[i] = c.get(i, 0) + 1\n\nways = 0\nfor i in a:\n ways += c[i]*(c[i]-1)//2\n\nfor k in a:\n ans = ways-c[k]+1\n print(ans)\n', 'n = int(input())\na = list(map(int, input().split()))\n\nb = set(a)\n\nc = {}\n\nfor i in b:\n c[i] = a.count(i)\n\nfor k in b:\n ans = 0\n for i in b:\n if i != k:\n ans += c[i]*(c[i]-1)//2\n else:\n ans += (c[i]-1)*(c[i]-2)//2\n print(ans)\n', 'n = int(input())\na = list(map(int, input().split()))\n\nb = set(a)\n\nc = {}\n\nfor i in a:\n c[i] = c.get(i, 0) + 1\n\ne = {}\nfor i in a:\n e[i] = c[i]*(c[i]-1)//2\n\nfor k in a:\n if d.get(k, "hello") == "hello":\n ans = 0\n for i in b:\n if i != k:\n ans += e[i]\n else:\n ans += e[i]+1-c[i]\n d[k] = ans\n else:\n ans = d[k]\n print(ans)\n', 'n = int(input())\na = list(map(int, input().split()))\n\nc = {}\n\nfor i in a:\n c[i] = c.get(i, 0) + 1\n\nways = 0\nfor i in c:\n ways += c[i]*(c[i]-1)//2\n\nd = {}\nfor k in a:\n if d.get(k, "hello") == "hello":\n ans = ways-c[k]+1\n d[k] = ans\n else:\n ans = d[k]\n print(ans)\n'] | ['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s135387768', 's858325965', 's897534296', 's963501510', 's639583715'] | [29476.0, 26140.0, 26140.0, 35616.0, 35116.0] | [2108.0, 368.0, 2104.0, 221.0, 444.0] | [397, 202, 273, 414, 298] |
p02732 | u880480312 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['import collections\nN=int(input())\nA = list(map(int,input().split()))\ncn = collections.Counter(A)\nprint(cn[A[2]])\nsumC=sum([n * (n-1)//2 for n in cn.values()])\nfor k in range(N):\n print(sumC-cn[A[k]]+1)\n\n\n', 'import collections\nN=int(input())\nA = list(map(int,input().split()))\ncn = collections.Counter(A)\nsumC=sum([n*(n-1)//2 for n in cn.values()])\nfor k in range(N):\n print(sumC-cn[A[k]]+1)\n\n\n'] | ['Wrong Answer', 'Accepted'] | ['s864393780', 's269333140'] | [26780.0, 26780.0] | [326.0, 340.0] | [207, 189] |
p02732 | u886655280 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['\n\nN = int(input())\nA_list = list(map(int, input().split()))\n\nbox = [0] * (N + 1)\nbox_2 = [0] * (N + 1)\nbox_3 = [0] * (N + 1)\n\nfor i in range(N):\n box[A_list[i] + 1] += 1\n\nfor i in range(N):\n if box[i] > 1:\n box_2[i] = (box[i] * (box[i] - 1)) / 2\n box_3[i] = ((box[i] - 1) * (box[i] - 2)) / 2\n\nans_base = sum(box_2)\n\nfor i in range(N):\n\n if box[A_list[i]] > 0:\n diff = box_2[A_list[i]] - box_3[A_list[i]]\n print(int(ans_base - diff))\n else:\n print(int(ans_base))\n \n', '\n\nN = int(input())\nA_list = list(map(int, input().split()))\n\nbox = [0] * (N + 1)\nbox_2 = [0] * (N + 1)\nbox_3 = [0] * (N + 1)\n\nfor i in range(N):\n box[A_list[i]] += 1\n\nfor i in range(N + 1):\n if box[i] > 1:\n box_2[i] = (box[i] * (box[i] - 1)) / 2\n box_3[i] = ((box[i] - 1) * (box[i] - 2)) / 2\n\nans_base = sum(box_2)\n\nfor i in range(N):\n\n if box[A_list[i]] > 0:\n diff = box_2[A_list[i]] - box_3[A_list[i]]\n print(int(ans_base - diff))\n else:\n print(int(ans_base))\n \n'] | ['Runtime Error', 'Accepted'] | ['s232132668', 's978530197'] | [26140.0, 26140.0] | [429.0, 420.0] | [565, 565] |
p02732 | u891422384 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['#count\nfor l in lis:\n if l in dic: dic[l] += 1\n else: dic[l] = 1\n\n#dic_sum = dic.copy()\ns = 0\n#calcurate\nfor d in dic:\n s += int(dic[d]*(dic[d]-1)/2)\n \nfor i in range(inp):\n \n t = dic[lis[i]]\n print(s-int(t*(t-1)/2)+int((t-1)*(t-2)/2))\n', 'inp = int(input())\nlis = list(map(int, input().split()))\n\ndic = {}\n\n#count\nfor l in lis:\n if l in dic: dic[l] += 1\n else: dic[l] = 1\n\n#dic_sum = dic.copy()\ns = 0\n#calcurate\nfor d in dic:\n s += int(dic[d]*(dic[d]-1)//2)\n \nfor i in range(inp):\n \n t = dic[lis[i]]\n print(s-int(t*(t-1)//2)+int((t-1)*(t-2)//2))'] | ['Runtime Error', 'Accepted'] | ['s434296053', 's572559401'] | [3060.0, 26140.0] | [17.0, 487.0] | [270, 340] |
p02732 | u893307213 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['import numpy as np\nimport math\ndef comb(n, r):\n return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))\n\n\nN = int(input())\nA = list(map(int, input().split()))\n\n\n\n\n\n\nnp_A = np.array(A)\n\n\ndic = {}\n\n\n\ntmp_all = np.array(A)\nunique = np.unique(tmp_all)\nprint("unique:", unique)\nans_all = 0\nfor u in unique:\n count_u = np.count_nonzero(tmp_all==u)\n # print(f"u:{u}, count_u:{count_u}")\n if count_u < 2:\n continue\n # (count_u) C 2\n tmp = int(count_u*(count_u-1)/2)\n ans_all += tmp\n# print("all", ans_all)\n\n\n\nfor k in range(N):\n before = A[:k]\n after = A[k+1:]\n\n before.extend(after)\n tmp_k = np.array(before)\n\n k_unique = np.unique(tmp_k)\n ans = 0\n\n k_num = A[k]\n count_u = np.count_nonzero(tmp_k==k_num)\n if count_u < 2:\n ans_k = 1\n else:\n ans_k = int(count_u*(count_u-1)/2)\n \n print(ans_all-ans_k)\n', 'import numpy as np\nimport math\ndef comb(n, r):\n return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))\n\n\nN = int(input())\nA = list(map(int, input().split()))\n\n\n\n\n\n\nnp_A = np.array(A)\n\n\ndic = {}\n\n\n\ntmp_all = np.array(A)\nunique = np.unique(tmp_all)\nprint("unique:", unique)\nans_all = 0\nfor u in unique:\n count_u = np.count_nonzero(tmp_all==u)\n # print(f"u:{u}, count_u:{count_u}")\n if count_u < 2:\n continue\n # (count_u) C 2\n tmp = int(count_u*(count_u-1)/2)\n ans_all += tmp\n# print("all", ans_all)\n\n\n\nfor k in range(N):\n k_num = A[k]\n count_u = np.count_nonzero(tmp_all==k_num) \n print(ans_all-count_u+1)\n', 'import numpy as np\nimport math\ndef comb(n, r):\n return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))\n\n\nN = int(input())\nA = list(map(int, input().split()))\n\n\n\n\n\n\nnp_A = np.array(A)\n\n\ndic = {}\n\nfor k in range(N):\n before = A[:k]\n after = A[k+1:]\n\n before.extend(after)\n tmp_k = np.array(before)\n \n \n\n \n \n\n k_unique = np.unique(tmp_k)\n ans = 0\n\n \n \n maped_num = map(str, k_unique) \n str_unique = "".join(maped_num.tolist())\n \n\n \n count_u_list = []\n for u in k_unique:\n count_u = np.count_nonzero(tmp_k==u)\n count_u_list.append(count_u)\n \n maped_num = map(str, count_u_list) \n str_count = "".join(maped_num.tolist())\n # str_count = "".join(count_u_list)\n # print("str_count", str_count)\n\n key = str_unique+str_count\n\n if key in dic.keys():\n print(dic[key])\n continue\n else:\n for count_u in count_u_list:\n if count_u < 2:\n continue\n # (count_u) C 2\n tmp = comb(count_u,2)\n ans += tmp\n\n \n dic[key] = ans\n print(ans)\n', 'import numpy as np\nimport math\ndef comb(n, r):\n return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))\nfrom collections import Counter\n\n\nN = int(input())\nA = list(map(int, input().split()))\nc = Counter(A)\nnp_A = np.array(A)\n\n\ntmp_all = np.array(A)\nunique = np.unique(tmp_all)\nprint("unique:", unique)\nans_all = 0\nfor u in unique:\n count_u = c[u]\n # print(f"u:{u}, count_u:{count_u}")\n if count_u < 2:\n continue\n # (count_u) C 2\n tmp = int(count_u*(count_u-1)/2)\n ans_all += tmp\n# print("all", ans_all)\n\n\n\nfor i in A:\n print(ans_all - c[i] + 1)\n', 'import numpy as np\nfrom collections import Counter\n\n\nN = int(input())\nA = list(map(int, input().split()))\nc = Counter(A)\nnp_A = np.array(A)\n\n\ntmp_all = np.array(A)\nunique = np.unique(tmp_all)\n\nans_all = 0\nfor u in unique:\n count_u = c[u]\n # print(f"u:{u}, count_u:{count_u}")\n if count_u < 2:\n continue\n # (count_u) C 2\n tmp = int(count_u*(count_u-1)/2)\n ans_all += tmp\n# print("all", ans_all)\n\n\n\nfor i in A:\n print(ans_all - c[i] + 1)\n'] | ['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s143799896', 's584620370', 's584912018', 's861834874', 's027813756'] | [34176.0, 34180.0, 34156.0, 34176.0, 34164.0] | [2110.0, 2109.0, 267.0, 686.0, 711.0] | [1120, 894, 1693, 666, 564] |
p02732 | u895592784 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ["N = int(input())\nA = list(map(int, input().split(' ')))\nnum_sum = 0\nfor i in range(1, N+1):\n c = A.count(i)\n num_sum += int(c * (c - 1) / 2)\n\nfor j in A:\n if A.count(j) == 1:\n print(sum(num_sum))\n else:\n print(sum(num_sum) - (A.count(j) - 1))", "N = int(input())\nA = list(map(int, input().split(' ')))\nnum_sum = 0\nfor i in range(1, N+1):\n c = A.count(i)\n num_sum += int(c * (c - 1) / 2)\n\nfor j in A:\n if A.count(j) == 1:\n print(sum(num_list))\n else:\n print(sum(num_list) - (A.count(j) - 1))", '\nimport collections\nN = int(input())\nA = list(map(int, input().split()))\ncnt = collections.Counter(A) \ntotal = 0\nfor key in cnt.keys():\n total += cnt[key] * (cnt[key] - 1) // 2\nfor i in range(N):\n tmp = total\n print(tmp - (cnt[A[i]] - 1))\n# tmp -= cnt[A[i]] * (cnt[A[i]] - 1) // 2\n# tmp += (cnt[A[i]] - 1) * (cnt[A[i]] - 2) // 2'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s212885423', 's597060594', 's760254165'] | [26268.0, 26012.0, 26780.0] | [2104.0, 2104.0, 377.0] | [268, 270, 930] |
p02732 | u898058223 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['n=int(input())\na=list(map(int,input().split()))\nb=[0]*n\ncnt=0\nfor i in a:\n b[i-1]+=1\ncnt=sum(b)\nfor i in a:\n print(cnt+(1-b[i-1]))', 'n=int(input())\na=list(map(int,input().split()))\nb=[0]*n\ncnt=0\nfor i in a:\n b[i-1]+=1\nfor i in b:\n cnt+=i*(i-1)//2\nfor i in a:\n print(cnt+(1-b[i-1]))'] | ['Wrong Answer', 'Accepted'] | ['s441434276', 's705652177'] | [26268.0, 26140.0] | [290.0, 328.0] | [132, 151] |
p02732 | u903699277 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['import copy\ndef combinations_count(n, r):\n return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))\n\ndef D159():\n N = int(input())\n A = input().split()\n \n for i in range(0, N):\n sum = 0\n A_ = copy.deepcopy(A)\n del A_[i]\n num = list(set(A_))\n for j in num:\n if A_.count(j) > 1:\n sum += combinations_count(A_.count(j), 2)\n print(sum)', 'N = int(input())\nA = input().split()\ntmp = 0\nidx = list(set(A))\nvalue = [ A.count(_) for _ in idx ]\nfor n in value:\n tmp += combi(n)\n\nfor i in A:\n j = idx.index(i)\n \n print(int(tmp - combi(value[j]) + combi(value[j]-1)))', 'N = int(input())\nA = list(map(int, input().split()))\n \nimport collections\nA_count = collections.Counter(A)\n \nimport math\nsum_ = 0\nfor ai in A_count:\n sum_ += (A_count[ai] * (A_count[ai] - 1)) // 2\n \nfor ai in A:\n #print(sum_ - (A_count[ai] * (A_count[ai] - 1)) // 2 + (A_count[ai] - 1) * (A_count[ai] - 2)) // 2\n l = A_count[ai] * (A_count[ai] - 1) // 2\n m = (A_count[ai] - 1) * (A_count[ai] - 2) // 2\n print(sum_ - l + m)'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s079409465', 's545716852', 's811526479'] | [3444.0, 24220.0, 25716.0] | [22.0, 2104.0, 523.0] | [437, 275, 437] |
p02732 | u913662443 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ["stdin =open(0).read().split('\\n')\nN=int(stdin[0])\nA=list(map(int,stdin[1].split()))\nfrom collections import Counter\nC=Counter(A)\nans=0\nfor i in set(A):\n d[i]=A.count(i)\n ans+=d[i]*(d[i]-1)//2\nfor a in A:\n num = C[a]\n print(ans-num*(num-1)//2+(num-1)*(num-2)//2)", "stdin =open(0).read().split('\\n')\nN=int(stdin[0])\nA=list(map(int,stdin[1].split()))\nfrom collections import Counter\nC=Counter(A)\nans=0\nfor i in C.values():\n ans+=i*(i-1)//2\nfor a in A:\n num = C[a]\n print(ans-num*(num-1)//2+(num-1)*(num-2)//2)"] | ['Runtime Error', 'Accepted'] | ['s800428889', 's907685576'] | [27412.0, 26180.0] | [117.0, 407.0] | [273, 251] |
p02732 | u915879510 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['import numpy as np\n\nn = int(input())\n\na = np.array(list(map(int, input().split())))\nd = [0] * n\ns = {}\n\nfor i in a:\n d[i-1] += 1\n \nsum = 0\nfor k in d:\n if k>1:\n sum += (k*(k-1))//2\n\nfor i in range(n):\n nd = d[a[i]]\n ans = sum-(nd*(nd-1))//2\n nd -= 1\n if nd>1:\n ans += (nd*(nd-1))//2\n print(ans)\n', 'import numpy as np\n\nn = int(input())\n\na = np.array(list(map(int, input().split())))\nd = [0] * (n+1)\ns = {}\n\nfor i in a:\n d[i] += 1\n \nsum = 0\nfor k in d:\n if k>1:\n sum += (k*(k-1))//2\n\nfor i in range(n):\n nd = d[a[i]]\n ans = sum-(nd*(nd-1))//2\n nd -= 1\n if nd>1:\n ans += (nd*(nd-1))//2\n print(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s111800549', 's087804101'] | [34156.0, 36204.0] | [775.0, 663.0] | [309, 311] |
p02732 | u920103253 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ["def n0():return int(input())\ndef n1():return [int(x) for x in input().split()]\ndef n2(n):return [int(input()) for _ in range(n)]\ndef n3(n):return [[int(x) for x in input().split()] for _ in range(n)]\n\ndef main()\n n=n0()\n a=n1()\n\n from math import factorial\n def comb(n):\n if n<=1:\n return 0\n if n==2:\n return 1\n return factorial(n)//(factorial(2)*factorial(n-2))\n\n c=[a.count(i) for i in range(1,n+1)]\n d=[comb(m) for m in c]\n s=sum(d)\n\n for i in range(n):\n print(s-d[a[i]-1]+comb(c[a[i]-1]-1))\nif __name__ == '__main__':\n \tmain()", "def n0():return int(input())\ndef n1():return [int(x) for x in input().split()]\ndef n2(n):return [int(input()) for _ in range(n)]\ndef n3(n):return [[int(x) for x in input().split()] for _ in range(n)]\n\ndef main()\n n=n0()\n a=n1()\n\n from math import factorial\n def comb(n):\n if n<=1:\n return 0\n if n==2:\n return 1\n return factorial(n)//(factorial(2)*factorial(n-2))\n\n c=[a.count(i) for i in range(1,n+1)]\n d=[comb(m) for m in c]\n s=sum(d)\n\n for i in range(n):\n print(s-d[a[i]-1]+comb(c[a[i]-1]-1))\nif __name__ == '__main__':\n\tmain()", "def n0():return int(input())\ndef n1():return [int(x) for x in input().split()]\ndef n2(n):return [int(input()) for _ in range(n)]\ndef n3(n):return [[int(x) for x in input().split()] for _ in range(n)]\n\ndef main()\n n=n0()\n a=n1()\n\n from math import factorial\n def comb(n):\n if n<=1:\n return 0\n if n==2:\n return 1\n return factorial(n)//(factorial(2)*factorial(n-2))\n\n c=[a.count(i) for i in range(1,n+1)]\n d=[comb(m) for m in c]\n s=sum(d)\n\n for i in range(n):\n print(s-d[a[i]-1]+comb(c[a[i]-1]-1))\nif __name__ == '__main__':", 'def n0():return int(input())\ndef n1():return [int(x) for x in input().split()]\ndef n2(n):return [int(input()) for _ in range(n)]\ndef n3(n):return [[int(x) for x in input().split()] for _ in range(n)]\n\nn=n0()\na=n1()\n\nfrom scipy.misc import comb\ndef combi(n):\n if n<=1:\n return 0\n if n==2:\n return 1\n return comb(n,2)\n\nc=[a.count(i) for i in range(1,n+1)]\nd=[combi(m) for m in c]\ns=sum(d)\n\nfor i in range(n):\n print(s-d[a[i]-1]+combi(c[a[i]-1]-1))', 'def n0():return int(input())\ndef n1():return [int(x) for x in input().split()]\ndef n2(n):return [int(input()) for _ in range(n)]\ndef n3(n):return [[int(x) for x in input().split()] for _ in range(n)]\n\nn=n0()\na=n1()\n\ndef comb(n):\n if n<=1:\n return 0\n if n==2:\n return 1\n return (n*(n-1))//2\n\nfrom collections import Counter\nc=Counter(a)\n# print(c)\nd={i:comb(j) for i,j in c.items()}\n# print(d)\ns=sum(d.values())\n# print(s)\n\nfor i in a:\n print(s-d[i]+comb(c[i]-1))'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s160867272', 's329810936', 's507049923', 's711686785', 's885610348'] | [2940.0, 2940.0, 2940.0, 26140.0, 32156.0] | [17.0, 17.0, 17.0, 2109.0, 433.0] | [605, 603, 595, 471, 488] |
p02732 | u922449550 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['N = int(input())\nA = list(map(int, input().split()))\n\nd = {}\nfor a in A:\n if a in d:\n d[a] += 1\n else:\n d[a] = 1\n\nans = 0\nfor a in d:\n n = d[a]\n ans += n * (n-1) // 2\n\nprint(ans)\nfor a in A:\n n = d[a]\n if n >= 2:\n print(ans - n + 1)\n else:\n print(ans)', 'N = int(input())\nA = list(map(int, input().split()))\n\nd = {}\nfor a in A:\n if a in d:\n d[a] += 1\n else:\n d[a] = 1\n\nans = 0\nfor a in d:\n n = d[a]\n ans += n * (n-1) // 2\n\nfor a in A:\n n = d[a]\n if n >= 2:\n print(ans - n + 1)\n else:\n print(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s841274880', 's166413225'] | [26140.0, 24748.0] | [350.0, 362.0] | [300, 290] |
p02732 | u927839462 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['n=int(input())\na=list(map(int, input().split()))\nimport collections\nimport math\ndef combinations_count(n, r):\n if(n<=1):\n answer=0\n else:\n answer=math.factorial(n) // (math.factorial(n - r) * math.factorial(r))\n return answer\n\ntable=collections.Counter(a)\nkeytable=collections.Counter(a).keys()\nc=[]\n\nfor key in keytable:\n c.append(table[key])\nprint(c)\nca=[]\nfor j in range(len(c)):\n ca.append(combinations_count(c[j], 2))\nprint(ca)\nsums=sum(ca)\nprint(sum)\nprint(keytable)\nprint(table)\nfor i in range(len(a)):\n keynum=list(keytable).index(a[i])\n answer=sums-ca[keynum]+combinations_count(c[keynum]-1, 2)\n print(answer)', 'n=int(input())\na=list(map(int, input().split()))\nimport collections\nimport math\ndef combinations_count2(n):\n if(n<=1):\n answer=0\n else:\n answer=n*(n-1)/2\n return answer\n\ntable=collections.Counter(a)\nkeytable=table.keys()\nc=[]\n\nfor key in keytable:\n c.append(table[key])\n#print(c)\nca=[]\nfor j in range(len(c)):\n ca.append(c[j]*(c[j])/2)\n#print(ca)\nsums=sum(ca)\n#print(sum)\n\n#print(table)\nfor i in range(len(a)):\n keynum=list(keytable).index(a[i])\n answer=sums-ca[keynum]+(c[keynum]-1)*(c[keynum]-2)/2\n print(int(answer))', 'n=int(input())\na=list(map(int, input().split()))\nimport collections\nimport math\ndef combinations_count2(n):\n if(n<=1):\n answer=0\n else:\n answer=n*(n-1)/2\n return answer\n\ntable=collections.Counter(a)\nkeytable=table.keys()\nsums=0\nfor value in table.values():\n sums+=combinations_count2(value)\n#print(ca)\n#print(sum)\n\n#print(table)\nfor i in range(len(a)):\n answer=sums-table[a[i]]+1\n print(int(answer))'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s635701323', 's896987078', 's530646099'] | [47720.0, 26140.0, 26140.0] | [2108.0, 2105.0, 451.0] | [656, 573, 447] |
p02732 | u928713799 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['import math\nimport collections\nfrom operator import mul\nfrom functools import reduce\n\ndef cmb(n,r):\n r = min(n-r,r)\n if r == 0: return 1\n over = reduce(mul, range(n, n - r, -1))\n under = reduce(mul, range(1,r + 1))\n return over // under\n\n\ndef combinations_count(n, r):\n\tif n < 2:\n\t\treturn 0\n\treturn math.factorial(n) // (math.factorial(n - r) * math.factorial(r))\n\n_ = int(input())\nns = input().split(" ")\ncs = collections.Counter(ns)\n\nc = 0\nfor n in ns:\n\tfor k, v in cs.items():\n\t\tif v==1:\n\t\t\tc += 0\n\t\telif n==k:\n#\t\t\tc += combinations_count(v-1, 2)\n\t\t\tc += cmb(v-1, 2)\n\t\telse:\n#\t\t\tc += combinations_count(v, 2)\n\t\t\tc += cmb(v, 2)\n\tprint(c)\n\tc = 0', 'N = int(input())\nA = [int(a)-1 for a in input().split()]\nX = [0] * N\nfor a in A:\n\tX[a] += 1\ns = 0\nfor x in X:\n\ts += x * (x-1) // 2\nprint(s)\nfor a in A:\n\tprint(s - (X[a] - 1))\n', 'import sys\ninput = sys.stdin.readline\nimport math\nimport collections\n\ndef combinations_count(n, r):\n\tif n < 2:\n\t\treturn 0\n\treturn math.factorial(n) // (math.factorial(n - r) * math.factorial(r))\n\n_ = int(input())\nns = input().split(" ")\ncs = collections.Counter(ns)\n\nc = 0\nfor n in ns:\n\tfor k, v in cs.items():\n\t\tif v==1:\n\t\t\tc += 0\n\t\telif n==k:\n#\t\t\tc += math.factorial(v-2)\n\t\t\tc += combinations_count(v-1, 2)\n\t\telse:\n#\t\t\tc += math.factorial(v-1)\n\t\t\tc += combinations_count(v, 2)\n\tprint(c)\n\tc = 0\n', 'N = int(input())\nA = [int(a)-1 for a in input().split()]\nX = [0] * N\nfor a in A:\n\tX[a] += 1\ns = 0\nfor x in X:\n\ts += x * (x-1) // 2\nfor a in A:\n\tprint(s - (X[a] - 1))\n'] | ['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s160972277', 's258439660', 's582627408', 's168790906'] | [26908.0, 26140.0, 26764.0, 25764.0] | [2105.0, 317.0, 2105.0, 308.0] | [661, 175, 496, 166] |
p02732 | u929768294 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['from collections import Counter\nN = int(input())\na = list(map(int, input().split()))\nc = Counter(a)\nprint(c.items())\nall=0\nfor i,j in c.items():\n all += j*(j-1)//2\nfor i in range(N):\n print(all-(a.count(a[i])-1))', 'from collections import Counter\nN = int(input())\na = list(map(int, input().split()))\nc = Counter(a)\nprint(c.items())\nall=0\nfor i,j in c.items():\n all += j*(j-1)//2\nfor i in range(N):\n print(all-(c[a[i]]-1))', 'from collections import Counter\nN = int(input())\na = list(map(int, input().split()))\nc = Counter(a)\n#print(c.items())\nall=0\nfor i,j in c.items():\n all += j*(j-1)//2\nfor i in range(N):\n print(all-(c[a[i]]-1))'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s632130279', 's851869091', 's318059961'] | [30100.0, 30236.0, 26780.0] | [2105.0, 425.0, 353.0] | [218, 212, 213] |
p02732 | u931636178 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['import sys\ndef II(): return int(sys.stdin.readline())\ndef MI(): return map(int, sys.stdin.readline().split())\nN = II()\nA = list(MI())\nans = 0\ncum = {}\ndef couple_combination(n):\n if n >= 2:\n return int(n * (n - 1) / 2)\n else:\n return 0\nfor unique in list(set(A)):\n cum_count = A.count(unique)\n cum[unique] = cum_count\n ans += couple_combination(cum_count)\nfor i in A:\n print(ans - cum[i])\n', 'import sys\nfrom collections import defaultdict\ndef II(): return int(sys.stdin.readline())\ndef MI(): return map(int, sys.stdin.readline().split())\nN = II()\nA = list(MI())\nans = 0\ncum = defaultdict(int)\ndef couple_combination(n):\n if n >= 2:\n return int(n * (n - 1) / 2)\n else:\n return 0\nfor v in A:\n cum[v] += 1\nfor v in cum.values():\n ans += couple_combination(v)\nfor v in A:\n print(max(0,ans - cum[v] + 1))\n'] | ['Wrong Answer', 'Accepted'] | ['s262226549', 's577891558'] | [24988.0, 25912.0] | [2104.0, 398.0] | [421, 437] |
p02732 | u934868410 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['from collections import defaultdict\nn = int(input())\na = list(map(int,input().split()))\nd = defaultdict(int)\nfor x in a:\n d[x] += 1\nfor x in a:\n c = d[x] - 1\n print(c * (c-1) // 2)', 'from collections import defaultdict\nn = int(input())\na = list(map(int,input().split()))\nd = defaultdict(int)\nfor x in a:\n d[x] += 1\nfor x in a:\n c = d[x] - 1\n print(c * (c-1) // 2)a', 'from collections import defaultdict\nn = int(input())\na = list(map(int,input().split()))\nd = defaultdict(int)\nfor x in a:\n d[x] += 1\n \ns = 0\nfor k,v in d.items():\n s += v * (v-1) // 2\nfor x in a:\n c = d[x] - 1\n print(s - c)'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s698867003', 's992494917', 's622438972'] | [25900.0, 2940.0, 26780.0] | [295.0, 17.0, 337.0] | [183, 184, 227] |
p02732 | u940533000 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['N = int(input())\nA = list(map(int, input().split()))\nB = sorted(A)\n\nall_c = 0\t\t\nidx = B[0]\nidx_count = 0\nidx_set = []\nfor i in range(N):\n if idx != B[i]:\n tmp1 = int(idx_count*(idx_count-1)/2)\t\t\n tmp2 = int((idx_count-1)*(idx_count-2)/2)\t\n all_c += tmp1\n idx_set.append([idx, tmp1, tmp2])\n idx_count = 0\n idx = B[i]\n idx_count+=1\nif idx_count != 0:\n tmp1 = int(idx_count*(idx_count-1)/2)\t\t\t\n tmp2 = int((idx_count-1)*(idx_count-2)/2)\t\t\n all_c += tmp1\n idx_set.append([idx, tmp1, tmp2])\n#print(idx_set)\nidx_sum_set = []\nfor i in range(len(idx_set)):\n all_c += idx_set[i][1]\nfor i in range(len(idx_set)):\n tmp = all_c-idx_set[i][1]+idx_set[i][2]\n idx_sum_set.append([idx_set[i][0], tmp]) \n\nfor i in range(N):\n j = int(len(idx_sum_set)/2)\n while 1:\n if A[i] == idx_sum_set[j][0]:\n print(idx_sum_set[j][1])\n break\n elif A[i] > idx_sum_set[j][0]:\n j = j + int((len(idx_sum_set)-j)/2)\n elif A[i] < idx_sum_set[j][0]:\n j = int(j/2)\n\n', 'import numpy as np\nN = int(input())\nA = list(map(int, input().split()))\nB = np.zeros(N+1)\n\nfor i in range(N):\n B[A[i]]+=1\n\n\nall_c = 0\nfor i in range(1,N+1):\n all_c += int(B[i]*(B[i]-1)/2)\t\t\t\nfor i in range(N):\n if B[A[i]] != 0:\n print(int(all_c-(B[A[i]]-1)))\n'] | ['Wrong Answer', 'Accepted'] | ['s515102674', 's200744404'] | [42944.0, 34156.0] | [2106.0, 1989.0] | [1254, 324] |
p02732 | u944325914 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['from collections import Counter\nn=int(input())\na=list(map(int,input().split()))\nb0=list(a[1:])\nc0=Counter(b0)\nd0=0\nfor i in c0:\n d0+=(c0[i])*(c0[i]-1)/2\nprint(d0)\nfor j in range(1,n-1):\n b=list(a[0:j])+list(a[j+1:])\n c=Counter(b)\n d=0\n for j in c:\n d+=(c[j])*(c[j]-1)/2\n print(d)\nb2=list(a[:-1])\nc2=Counter(b2)\nd2=0\nfor k in c2:\n d2+=(c2[k])*(c2[k]-1)/2\nprint(d2)\n', 'from copy import copy\nfrom collections import Counter\nn=int(input())\na=list(map(int,input().split()))\na_counter=Counter(a)\nans=0\nfor i in a_counter:\n ans+=(a_counter[i])*(a_counter[i]-1)//2\nfor j in a:\n true_ans=copy(ans)\n true_ans=true_ans-((a_counter[j])*(a_counter[j]-1)//2-(a_counter[j]-1)*(a_counter[j]-2)//2)\n print(true_ans)'] | ['Wrong Answer', 'Accepted'] | ['s353785206', 's063070606'] | [46576.0, 34084.0] | [2105.0, 357.0] | [392, 343] |
p02732 | u944643608 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['import numpy as np\nN = int(input())\nA = list(map(int, input().split()))\nA = np.array(A)\nans = np.zeros(N)\ntotal = 0\nfor i in range(N):\n ans[A[i] - 1] += 1\nfor i in range(N):\n total += ans[i] * (ans[i] - 1) // 2\nfor i in range(N):\n print(total - max(ans[A[i]-1]-1,0))\n ', 'import numpy as np\nfrom sys import stdin\ninput = stdin.readline\nN = int(input())\nA = list(map(int, input().split()))\nA = np.array(A)\nnumber = np.zeros(N, dtype = int)\nfor i in range(N):\n number[i] = A.count(i + 1)\ntotal = 0\nfor k in range(N):\n tmp = number[k]\n total += tmp * (tmp-1) // 2\nfor j in range(N):\n print(total - number[A[j]-1] + 1)\n', 'import numpy as np\nfrom sys import stdin\ninput = stdin.readline\nN = int(input())\nA = list(map(str, input().split()))\nA = np.array(A)\nnumber = np.zeros(N, dtype = int)\nfor i in range(N):\n number[i] = A.count(str(i + 1)\ntotal = 0\nfor k in range(N):\n tmp = number[k]\n total += tmp * (tmp-1) // 2\nfor j in range(N):\n print(total - number[A[j]-1] + 1)\n', 'import numpy as np\nfrom sys import stdin\ninput = stdin.readline\nN = int(input())\nA = list(map(str, input().split()))\nA = np.array(A)\nnumber = np.zeros(N, dtype = int)\nfor i in range(N):\n number[i] = A.count(str(i + 1))\ntotal = 0\nfor k in range(N):\n tmp = number[k]\n total += tmp * (tmp-1) // 2\nfor j in range(N):\n print(total - number[A[j]-1] + 1)\n', 'impot numpy as np\nN = int(input())\nA = list(map(int, input().split()))\nA = np.array(A)\nnumber = np.zeros(N, dtype = int)\nfor i in range(N):\n number[A[i]-1] += 1\ntotal = 0\nfor k in range(N):\n total += number[k] * (number[k]-1) // 2\nfor j in range(N):\n print(total - number[A[j]-1] + 1)\n', "import numpy as np\nfrom sys import stdin\ninput = stdin.readline\nN = int(input())\nA = list(map(str, input().split()))\nA = np.array(A)\nnumber = np.zeros(N, dtype = int)\nfor i in range(N):\n number[i] = A.count('i + 1')\ntotal = 0\nfor k in range(N):\n tmp = number[k]\n total += tmp * (tmp-1) // 2\nfor j in range(N):\n print(total - number[A[j]-1] + 1)\n", 'import numpy as np\nfrom sys import stdin\ninput = stdin.readline\nN = int(input())\nA = list(map(int, input().split()))\nnumber = np.zeros(N, dtype = int)\ntotal = 0\n\ndic = {}\na = sorted(A)\nnow_key = a[0]\nvalue = 1\ndic[now_key] = 1\nfor i in range(1,N):\n if a[i] == now_key:\n value += 1\n else:\n dic[now_key] = value\n if value >= 2:\n total += value * (value-1) // 2\n now_key = a[i]\n value = 1\ndic[now_key] = value\nif value >= 2:\n total += value * (value-1)//2\nfor j in A:\n print(total - dic[j] + 1)'] | ['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s064277130', 's259174336', 's530836719', 's672938074', 's952906367', 's999391760', 's399349849'] | [34152.0, 43060.0, 2940.0, 36964.0, 2940.0, 37068.0, 35872.0] | [2112.0, 363.0, 17.0, 204.0, 17.0, 212.0, 563.0] | [272, 347, 351, 352, 288, 349, 515] |
p02732 | u947101138 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['import copy\n\nN=int(input())\n\nA=list(map(int,input().split()))\n\n#print(A)\n\nmama=dict()\npapa=dict()\npapa[0]=0\npapa[1]=0\npapa[2]=1\nfor i in range(3,N/2):\n papa[i]=int(i*papa[i-1]/2)\nfor i in range(N):\n\n if(A[i] in mama):\n print(mama[A[i]])\n continue\n \n AA=copy.deepcopy(A)\n ai=A[i]\n del AA[i]\n #print(AA)\n Aset=set(AA)\n count=0\n \n for i in Aset:\n aa=AA.count(i)\n if(aa in papa):\n count+=papa[aa]\n continue\n #print(i,aa)\n aiu=int((aa*(aa-1))/2)\n count+=aiu\n papa[aa]=aiu\n print(count)\n mama[ai]=count\n', 'from collections import Counter\nN=int(input())\nA=list(map(int,input().split()))\n\nparent=dict()\nAn=set(A)\nparecou=0\naaa=Counter(A)\nfor i in aaa.values():\n parecou+=int((i*(i-1)/2))\n\n\n\n\nfor i in range(N):\n anko=aaa[A[i]]\n print(parecou-int((anko*(anko-1)/2))+int(((anko-2)*(anko-1)/2)))\n \n'] | ['Runtime Error', 'Accepted'] | ['s754488242', 's563341776'] | [26780.0, 28852.0] | [71.0, 526.0] | [614, 419] |
p02732 | u951113446 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['import itertools\n\nif __name__ == "__main__":\n N = int(input())\n A = input().split()\n all = len(tuple(filter(lambda t: t[0] == t[1], itertools.combinations(A, 2))))\n for x in range(N):\n count = A.count(A[x])\n tmp = tuple(["0" for _ in range(count)])\n result = tuple(filter(lambda t: t[0] == t[1], itertools.combinations(tmp, 2)))\n print(all-len(result))\n', 'import sys\nimport itertools\nfrom collections import Counter\nsys.setrecursionlimit(10**8)\nif __name__ == "__main__":\n N = int(input())\n A = input().split()\n counter = Counter(A)\n result = 0\n for c in counter.values():\n result += c*(c-1)//2\n for a in A:\n k = counter[a]\n print(result - k*(k-1)//2 + (k-1)*(k-2)//2)'] | ['Wrong Answer', 'Accepted'] | ['s389785207', 's155276605'] | [456100.0, 26784.0] | [2131.0, 390.0] | [393, 351] |
p02732 | u951480280 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['import math\n\ndef combinations_count(n, r):\n return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))\n\nn = int(input())\na = sorted(map(int,input().split()))\ncnt = []\ncnt1 = 1\nfor i in range(1,n):\n if a[i] == a[i-1]:\n cnt1 += 1\n if i == n-1:\n cnt.append(cnt1)\n else:\n cnt.append(cnt1)\n cnt1 = 1\n if i == n-1:\n cnt.append(cnt1)\n\ncnt_s = set(cnt)\ncmb_patern = {}\n\nfor c in cnt_s:\n if c not in cmb_patern.keys():\n if c >= 3:\n cmb_patern[c] = [combinations_count(c,2), combinations_count(c-1,2)]\n elif c == 2:\n cmb_patern[c] = [1,0]\n else:\n continue\n\ncmb = [0] * len(cnt)\n\nfor i in range(len(cnt)):\n if cnt[i] >= 2:\n cmb[i] = cmb_patern[cnt[i]][0]\n\ncmb_all = sum(cmb)\n\nfor i in range(len(cnt)):\n if cnt[i] == 1:\n print(cmb_all)\n elif cnt[i] == 2:\n print(cmb_all - 1)\n print(cmb_all - 1)\n else:\n ans = cmb_all - cmb[i] + cmb_patern[cnt[i]][1]\n for j in range(cnt[i]):\n print(ans)\n', 'import math\n\ndef combinations_count(n, r):\n return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))\n\nn = int(input())\na = sorted(map(int,input().split()))\ncnt = []\ncnt1 = 1\nfor i in range(1,n):\n if a[i] == a[i-1]:\n cnt1 += 1\n if i == n-1:\n cnt.append(cnt1)\n else:\n cnt.append(cnt1)\n cnt1 = 1\n if i == n-1:\n cnt.append(cnt1)\n\ncmb = {}\n\nfor i in range(len(cnt)):\n if cnt[i] >= 2:\n cmb[cnt[i]] = combinations_count(cnt[i],2)\n\ncmb_all = sum(cmb.values())\n\nfor i in range(len(cnt)):\n if cnt[i] == 1:\n print(cmb_all)\n elif cnt[i] == 2:\n print(cmb_all - 1)\n print(cmb_all - 1)\n else:\n ans = cmb_all - cmb[cnt[i]] + combinations_count(cnt[i]-1, 2)\n for j in range(cnt[i]):\n print(ans)\n', 'import math\n\ndef combinations_count(n, r):\n return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))\n\nn = int(input())\na = list(map(int,input().split()))\na1 = sorted(a)\ncnt = {}\ncnt1 = 1\nfor i in range(1,n):\n if a1[i] == a1[i-1]:\n cnt1 += 1\n if i == n-1:\n cnt[a1[i]] = cnt1\n else:\n cnt[a1[i-1]] = cnt1\n cnt1 = 1\n if i == n-1:\n cnt[a1[i]] = cnt1\n\n\ncmb = {}\ncmb[1] = 0\ncmb_all = 0\nfor i in cnt.values():\n if i == 1:\n continue\n else:\n cmb1 = combinations_count(i,2)\n cmb_all += cmb1\n cmb[i] = cmb1\n\nfor i in a:\n cnt1 = cnt[i]\n if cnt1 == 1:\n print(cmb_all)\n else:\n ans = cmb_all + cmb[cnt1] * ((cnt1-2)/cnt1 - 1)\n print(int(ans))\n\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s752816775', 's882325845', 's978472361'] | [26140.0, 26140.0, 26652.0] | [2104.0, 2104.0, 1858.0] | [1076, 824, 773] |
p02732 | u952669998 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ["def main():\n import sys\n input = sys.stdin.readline\n import numpy as np\n from collections import Counter\n\n N = int(input())\n A = list(map(int,input().split()))\n print(set(A))\n c = Counter(A)\n\n tmp = np.array(list(c.values()))\n l1= tmp*(tmp-1)//2\n l2= (tmp-1)*((tmp-1)-1)//2\n S = np.sum(l1)\n\n for a in A:\n r = list(c).index(a)\n sum = S + l2[r] -l1[r]\n print(int(sum))\n\nif __name__ == '__main__':\n main()\n", 'n=int(input())\nA=list(map(int,input().split()))\n\nimport collections \nc=collections.Counter(A)\nsum=0\nfor i in c:\n sum+=c[i]*(c[i]-1)//2 \nfor a in A:\n print(sum - c[a]*(c[a]-1)//2 + (c[a]-1)*(c[a]-2)//2)'] | ['Wrong Answer', 'Accepted'] | ['s071813282', 's817564498'] | [35940.0, 26140.0] | [2109.0, 485.0] | [426, 204] |
p02732 | u952968889 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['n=int(input())\na=list(map(int,input().split()))\n\nfrom collections import Counter\nc=Counter(A)\n\nANS=0\t# max combination\nfor i in C.values():\n ANS+=i*(i-1)//2 # 6+1+1 = 8\n \nfor a in A:\n k=C[a] # 4 2 4 2 2 4 2 4\n \n print(ANS-(k*(k-1)//2)+((k-1)*(k-2)//2)) # different from max combination\n # 8 - 6 + 3\n # 5', 'n=int(input())\na=list(map(int,input().split()))\n \nfrom collections import Counter\nc=Counter(a)\n \nmax_c=0\t\t\t# max combination\nfor i in c.values():\n max_c+=i*(i-1)//2 # 6+1+1 = 8\n \nfor num in a:\n k=c[num] # 4 2 4 2 2 4 2 4\n \n print(ans-(k*(k-1)//2)+((k-1)*(k-2)//2)) # different from max combination\n # 8 - 6 + 3\n # 5', 'n=int(input())\na=list(map(int,input().split()))\n \nfrom collections import Counter\nc=Counter(a)\n \nmax_c=0\t\t\t# max combination\nfor i in c.values():\n max_c+=i*(i-1)//2 # 6+1+1 = 8\n \nfor num in a:\n k=c[num] # 4 2 4 2 2 4 2 4\n \n print(max_c-(k*(k-1)//2)+((k-1)*(k-2)//2)) # different from max combination\n # 8 - 6 + 3\n # 5'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s155973049', 's695884076', 's480344481'] | [26012.0, 25376.0, 26140.0] | [73.0, 136.0, 398.0] | [351, 363, 365] |
p02732 | u953794676 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ["n = 8\na = list(map(int, '1 2 1 4 2 1 4 1'.split()))\ncount_dict = {}\ntotal_sum = 0\nfor i in a:\n if i not in count_dict:\n count_dict[i] = a.count(i)\n total_sum += (a.count(i))*(a.count(i)-1)//2\nfor i in a:\n print(total_sum - (a.count(i)*(a.count(i)-1)//2) + (a.count(i)-1)*(a.count(i)-2)//2)", 'import collections\nn = int(input())\na = list(map(int, input().split()))\ncnt = collections.Counter(a)\ntotal = 0\nfor key in cnt.keys():\n total += cnt[key]*(cnt[key]-1) // 2\nfor i in a:\n ans = total\n ans -= cnt[i] * (cnt[i]-1) / 2\n ans += (cnt[i]-1) * (cnt[i]-2) / 2\n print(ans)', 'n = int(input())\na = list(map(int, input().split()))\ndiff_dict = {}\ntotal_sum = 0\nfor i in a:\n if i not in diff_dict:\n temp = (count_dict[i])*(count_dict[i]-1)//2\n diff_dict[i] = temp-(count_dict[i]-1)*(count_dict[i]-2)//2\n total_sum += temp\nfor i in a:\n print(total_sum - diff_dict[i])', 'import collections\nn = int(input())\na = list(map(int, input().split()))\ncnt = collections.Counter(a)\ntotal = 0\nfor key in cnt.keys():\n total += cnt[key]*(cnt[key]-1) // 2\nfor i in a:\n ans = total\n ans -= cnt[i] * (cnt[i]-1) / 2\n ans += (cnt[i]-1) * (cnt[i]-2) / 2\n print(int(ans))'] | ['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s029813068', 's731717070', 's935927296', 's605013022'] | [3060.0, 26772.0, 26140.0, 26772.0] | [17.0, 625.0, 66.0, 575.0] | [309, 290, 313, 295] |
p02732 | u954153335 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['import math\nimport collections\ndef calc_combi2(n):\n if n<=1:\n return 0\n return math.factorial(n)/(math.factorial(n-2)*math.factorial(2))\nn=int(input())\ndata=list(map(int,input().split()))\ndata_cnt=collections.Counter(data)\ncount=0\nfor i in data_cnt.values():\n if 2<=i:\n count+=calc_combi2(i)\nfor i in data:\n if i<=1:\n print(count)\n else:\n ans=count+(calc_combi2(data_cnt[i]-1)-calc_combi2(data_cnt[i]))\n print(int(ans))', 'import math\nimport collections\ndef calc_combi2(n):\n if n<=1:\n return 0\n return math.factorial(n)/(math.factorial(n-2)*math.factorial(2))\nn=int(input())\ndata=list(map(int,input().split()))\ndata_cnt=collections.Counter(data)\nans=[0]*n\ncount=0\nfor i in data_cnt.values():\n count+=calc_combi2(i)\nfor a,b in data_cnt.items():\n if 2<=b:\n ans[a]=int(count-b+1)\nfor i in data:\n print(ans[i-1])', 'import math\nimport collections\ndef calc_combi2(n):\n if n<=1:\n return 0\n return math.factorial(n)/(math.factorial(n-2)*math.factorial(2))\nn=int(input())\ndata=list(map(int,input().split()))\ndata_cnt=collections.Counter(data)\ncount=0\nans=collections.Counter()\nfor i in data_cnt.values():\n count+=calc_combi2(i)\nfor a,b in data_cnt.items():\n if 2<=b:\n ans[a]=int(count-b+1)\n else:\n ans[a]=int(count)\nfor i in data:\n print(ans[i])'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s540668407', 's610692739', 's502376970'] | [26772.0, 26772.0, 36084.0] | [2104.0, 1636.0, 1649.0] | [469, 414, 464] |
p02732 | u956277093 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['n = int(input())\nl = list(map(int,input().split()))\nif len(set(l))==len(l):\n for i in range(len(l)):\n print(0)\nelif len(set(l))==1:\n for i in range(n):\n print((n*(n-1)//2)-n+1)\nelse:\n d = {}\n for i in l:\n if i in d:\n d[i]+=1\n else:\n d[i] = 1\n for i in l:\n d[i] -= 1\n print(sum(set(d.values())))\n d[i] += 1', 'n = int(input())\nl = list(map(int,input().split()))\nif len(set(l))==len(l):\n for i in range(len(l)):\n print(0)\nelif len(set(l))==1:\n for i in range(len(l)):\n print(n+1)\nelse:\n for k in range(len(l)):\n tp = l.pop(k)\n print(sum(set([l.count(i) for i in l])))\n l.insert(k,tp)', 'n = int(input())\nl = list(map(int,input().split()))\nif len(set(l))==len(l):\n for i in range(len(l)):\n print(0)\nelif len(set(l))==1:\n for i in range(len(l)):\n print(n+1)\nelse:\n kp = list(set(l))\n print(kp)\n dt = {}\n for i in range(len(kp)):\n tp = kp[i]\n l.remove(kp[i])\n dt[tp]= sum(set([l.count(i) for i in l]))\n l.insert(i,tp)\n print(dt)\n for i in l:\n print(dt[i])\n', 'n = int(input())\nl = list(map(int,input().split()))\nd = {}\nfor i in l:\n if i in d:\n d[i]+=1\n else:\n d[i] = 1\ncp = 0\nfor i in d.values():\n cp+= i*(i-1)//2\nfor i in l:\n print(cp-d[i]+1)'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s041730576', 's334659163', 's773449413', 's628352277'] | [29220.0, 26140.0, 26140.0, 26140.0] | [2105.0, 2104.0, 2105.0, 348.0] | [391, 316, 443, 209] |
p02732 | u959340534 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | [' = int(input())\nimport numpy as np\n\nA = list(map(int, input().split()))\ndp = np.zeros((N,N), dtype=np.int32)\nfor i in range(N):\n tmp = [0]*(A[i]-1)+[1]+[0]*(N-A[i])\n tmp = np.array(tmp, dtype=np.int32)\n dp[i] = tmp+dp[i-1]\n\ndp = np.array(dp)\nans = []\nfor i in range(N):\n if i > 0 and i < N-1:\n tmp = dp[N-1] - dp[i] + dp[i-1]\n tmp = tmp*(tmp-1)//2\n tmp = tmp[tmp>0]\n ans.append(tmp.sum(dtype=np.int32))\n if i == 0:\n tmp = dp[N-1] - dp[i]\n tmp = tmp*(tmp-1)//2\n tmp = tmp[tmp>0]\n ans.append(tmp.sum(dtype=np.int32))\n if i == N-1:\n tmp = dp[N-2]\n tmp = tmp*(tmp-1)//2\n tmp = tmp[tmp>0]\n ans.append(tmp.sum(dtype=np.int32))\nfor i in ans:\n print(i)', 'N = int(input())\nA = list(map(int, input().split()))\n\nfrom collections import defaultdict\nc = defaultdict(int)\ncm = set()\nc2 = list()\nnum = 0\nfor i in range(N):\n c[A[i]] += 1\n cm.add(A[i])\nfor i in list(cm):\n num += c[i]*(c[i]-1)//2\nfor i in range(N):\n ans = num - c[A[i]] + 1\n c2.append(ans)\n\nfor cs in c2:\n print(cs)'] | ['Runtime Error', 'Accepted'] | ['s339063585', 's955287128'] | [2940.0, 31644.0] | [17.0, 432.0] | [687, 324] |
p02732 | u968404618 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['import sys\ninput = lambda: sys.stdin.readline().rstrip()\n\ndef choose2(n):\n return n*(n-1)//2\n\nn = int(input())\nA = list(map(int, input().split()))\n\nCnt = [(a-1) for a in A]\n\ntot = 0\nfor i in range(n):\n tot += choose2(Cnt[i])\n\nfor i in range(n):\n ans = tot\n ans -= choose2(Cnt[A[i]])\n ans += choose2(Cnt[A[i]]-1)\n print(ans)', 'import sys\ninput = lambda: sys.stdin.readline().rstrip()\n\ndef choose2(n):\n return n*(n-1)//2\n\nn = int(input())\nA = list(map(int, input().split()))\nA = [a-1 for a in A]\n \nCnt = [0]*n\nfor i in range(n):\n Cnt[A[i]] += 1\n \ntot = 0\nfor i in range(n):\n tot += choose2(Cnt[i])\n\nfor i in range(n):\n ans = tot\n ans -= choose2(Cnt[A[i]])\n ans += choose2(Cnt[A[i]]-1)\n print(ans)'] | ['Runtime Error', 'Accepted'] | ['s608261541', 's065412967'] | [26268.0, 26268.0] | [483.0, 492.0] | [341, 391] |
p02732 | u969133463 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['import math\nn = int(input())\na = list(map(int,input().split()))\nmx = max(a)\nb=[0] * 2000000\nans = 0\nfor i in range(len(a)):\n b[a[i]-1] += 1\n\nfor i in range(mx):\n if(b[i] == 0 or b[i] == 1):\n ans += 0\n else:\n ans = ans + int(b[i] * (b[i]-1)/2)\nans1 = 0\n\n\nfor i in range(len(a)):\n ans1 = ans\n if(b[a[i]-1] >2):\n ans1 = ans1 -int((b[a[i]-1]-(b[a[i]-1]-1))/2)+ int(((b[a[i]-1]-1) * (b[a[i]-1]-2))/2)\n print(int(ans1))\n elif(b[a[i]-1] == 2):\n print(int(ans1-1))\n elif(b[a[i]-1] < 2):\n print(int(ans1))', 'import math\nn = int(input())\na = list(map(int,input().split()))\nmx = max(a)\nb=[0] * 2000000\nans = 0\nfor i in range(len(a)):\n b[a[i]-1] += 1\n\nfor i in range(mx):\n if(b[i] == 0 or b[i] == 1):\n ans += 0\n else:\n ans = ans + int(b[i] * (b[i]-1)/2)\nans1 = 0\n\n\nfor i in range(len(a)):\n ans1 = ans\n if(b[a[i]-1] >2):\n ans1 = ans1 -int((b[a[i]-1]*(b[a[i]-1]-1))/2) + int(((b[a[i]-1]-1) * (b[a[i]-1]-2))/2)\n print(int(ans1))\n elif(b[a[i]-1] == 2):\n print(int(ans1-1))\n elif(b[a[i]-1] < 2):\n print(int(ans1))'] | ['Wrong Answer', 'Accepted'] | ['s363023055', 's342329872'] | [31840.0, 31844.0] | [558.0, 579.0] | [559, 560] |
p02732 | u973972117 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['N = int(input())\nK = list(map(int,input().split()))\nA = [0]*N\nprint(A)\nfor i in range(N):\n A[K[i]-1] += 1\nr = 0\nfor k in range(N):\n r += 0.5*(A[k]*(A[k]-1))\nAn =[]\nfor j in range(N):\n D = A[K[j]-1]-1\n An.append(int(r-(0.5*(D+1)*(D))+(0.5*D*(D-1))))\nfor i in range(len(An)):\n print(An[i])', 'N = int(input())\nK = list(map(int,input().split()))\nA = [0]*N\nfor i in range(N):\n A[K[i]-1] += 1\nr = 0\nfor k in range(N):\n r += 0.5*(A[k]*(A[k]-1))\nAn =[]\nfor j in range(N):\n D = A[K[j]-1]-1\n An.append(int(r-(0.5*(D+1)*(D))+(0.5*D*(D-1))))\nfor i in range(len(An)):\n print(An[i])'] | ['Wrong Answer', 'Accepted'] | ['s717550033', 's778415442'] | [26268.0, 26140.0] | [513.0, 515.0] | [302, 293] |
p02732 | u976169012 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['n = int(input())\na = list(map(int,input().split()))\nd = {}\naa = [0]\nfor i in range(1,n):\n\taa.append(aa[-1]+i)\nfor i in a:\n\tif i not in d:\n\t\td[i] = 1\n\telse:\n\t\td[i]+=1\ns = 0\nfor i in d:\n\ts+=aa[d[i]-1]\ndd = {}\nfor i in d:\n\tif i not in dd:\n\t\tif d[i]!=1:\n\t\t\tdd[i] = (s-aa[d[i]-1]+aa[d[i]-2])\n\t\telse:\n\t\t\tdd[i] = 0\nprint(dd)\nfor i in a:\n\tprint(dd[i])', 'n = int(input())\na = list(map(int,input().split()))\nd = {}\naa = [0,0]\nfor i in range(1,n):\n\taa.append(aa[-1]+i)\nfor i in a:\n\tif i not in d:\n\t\td[i] = 1\n\telse:\n\t\td[i]+=1\ns = 0\nfor i in d:\n\ts+=aa[d[i]]\ndd = {}\nfor i in d:\n\tif i not in dd:\n\t\tdd[i] = (s-aa[d[i]]+aa[d[i]-1])\nfor i in a:\n\tprint(dd[i])'] | ['Wrong Answer', 'Accepted'] | ['s753096855', 's093073778'] | [43092.0, 44064.0] | [464.0, 412.0] | [343, 295] |
p02732 | u977193988 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['import sys\nimport numpy as np\n\n\ndef input():\n return sys.stdin.readline().strip()\n\n\ndef main():\n N = int(input())\n A = np.array(list(map(int, input().split())))\n List = np.unique(A)\n count = np.bincount(A)\n # print(count)\n\n dic = {}\n Ans = 0\n for l in List:\n n = count[l]\n num = n * (n - 1) // 2\n Ans += num\n dic[l] = num\n B = np.empty(N, dtype=np.int)\n for l in List:\n n = count[l] - 1\n num = n * (n - 1) // 2\n B = np.where(A == l, int(Ans - dic[l] + num), B)\n print(*B, sep="\\n")\n\n\nmain()\n', 'import sys\nfrom collections import Counter\n\n\ndef input():\n return sys.stdin.readline().strip()\n\n\ndef main():\n N = int(input())\n A = list(map(int, input().split()))\n C = Counter(A)\n total = 0\n for k, v in C.items():\n if v > 1:\n total += v * (v - 1) // 2\n\n for a in A:\n v = C[a]\n if v > 1:\n print(total - v * (v - 1) // 2 + (v - 1) * (v - 2) // 2)\n else:\n print(total)\n\n\nmain()\n'] | ['Time Limit Exceeded', 'Accepted'] | ['s422964225', 's098097474'] | [40152.0, 26780.0] | [2110.0, 335.0] | [576, 458] |
p02732 | u979362546 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['from collections import Counter\n\nn = int(input())\nA = list(map(int, input().split()))\ncounter = Counter(A)\nans = 0\n\nfor i in counter.values():\n\tans = i * (i - 1) // 2\n\nfor j in A:\n\tcnt = counter[j]\n\tif cnt <= 1:\n\t\tprint(ans)\n\telse:\n\t\tprint(ans - cnt + 1)', 'from collections import Counter\n\nn = int(input())\nA = list(map(int, input().split()))\ncounter = Counter(A)\nans = 0\n\nfor i in counter.values():\n\tans += i * (i - 1) // 2\n\nfor j in A:\n\tcnt = counter[j]\n\tif cnt <= 1:\n\t\tprint(ans)\n\telse:\n\t\tprint(ans - cnt + 1)'] | ['Wrong Answer', 'Accepted'] | ['s147146743', 's976611283'] | [26780.0, 26780.0] | [319.0, 365.0] | [254, 255] |
p02732 | u979444096 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['from collections import Counter\n\ndef main():\n N = int(input())\n A = list(map(int, input().split()))\n uq = list(set(A))\n ans_hash = {}\n num_hash = {}\n for u in uq:\n ans = 0\n a = A[:]\n i = a.index(u)\n del a[i]\n val = Counter(a).values()\n print("val: %s", val)\n for num in val:\n if num in num_hash:\n ans += num_hash[num]\n else:\n num_hash[num] = num * (num - 1) // 2\n ans += num_hash[num]\n ans_hash[u] = ans\n for n in A:\n if n in ans_hash:\n print(ans_hash[n])\n else:\n a = A[:]\n i = a.index(n)\n del a[i]\n val = Counter(a).values()\n for num in val:\n if num in num_hash:\n ans += num_hash[num]\n else:\n num_hash[num] = num * (num - 1) // 2\n ans += num_hash[num]\n ans_hash[n] = ans\n print(ans_hash[n])\n\n\nif __name__ == \'__main__\':\n main()\n', "from collections import Counter\n\ndef choose(n):\n return n * (n - 1) // 2\n\n\ndef main():\n N = int(input())\n A = list(map(int, input().split()))\n C = Counter(A)\n cnt = 0\n for c in C.values():\n cnt += choose(c)\n\n for a in A:\n ans = cnt\n ans -= choose(C[a])\n ans += choose(C[a] - 1)\n print(ans)\n\n\nif __name__ == '__main__':\n main()\n"] | ['Wrong Answer', 'Accepted'] | ['s355494615', 's972895626'] | [53644.0, 26780.0] | [2105.0, 417.0] | [1065, 386] |
p02732 | u981760053 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['N=int(input())\nlist1=list(map(int,input().split()))\nlist2=[0]*N\n\nfor i in range(N):\n list2[i]=list1.count(i+1)\n\ndef choose2(n):\n return n*(n-1)/2\n\ntotal=0\nfor i in list2:\n total+=choose2(i)\n\n\nfor i in list1:\n ans=total-(list2[i-1]-1)\n print(ans)', 'from collections import Counter\n\nN=int(input())\nlist1=list(map(int,input().split()))\n\ndic1=Counter(list1)\n\ndef choose2(n):\n return n*(n-1)/2\n\nsum=0\nfor key in dic1:\n sum+=choose2(dic1[key])\n\nfor i in list1:\n print(int(sum-dic1[i]+1))'] | ['Wrong Answer', 'Accepted'] | ['s758236662', 's514127152'] | [26140.0, 34116.0] | [2104.0, 251.0] | [260, 242] |
p02732 | u981931040 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['from collections import Counter\n\ndef cmb(n, r, mod=10**9+7):\n if ( r<0 or r>n ):\n return 0\n r = min(r, n-r)\n return g1[n] * g2[r] * g2[n-r] % mod\n\nmod = 10**9+7 \nN = 10**5 * 2 + 1\ng1 = [1, 1] \ng2 = [1, 1] \ninverse = [0, 1] 計算用テーブル\n\nfor i in range( 2, N + 1 ):\n g1.append( ( g1[-1] * i ) % mod )\n inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )\n g2.append( (g2[-1] * inverse[-1]) % mod )\n\n\n\nN = int(input())\nball_com = [0] * (N + 1)\nballs = list(map(int, input().split()))\nballs_counter = Counter(balls)\nfor key , val in balls_counter.items():\n ball_com[key - 1] = cmb(val, 2)\n\ncmb_sum = sum(ball_com)\nfor ball in balls:\n print(cmb_sum - ball_com[ball - 1] + cmb(balls_counter[ball] - 1, 2))\n', 'from collections import Counter\n\ndef cmb(n, r, mod=10**9+7):\n return n * (n - 1) // 2\n\n\n\nN = int(input())\nball_com = [0] * (N + 1)\nballs = list(map(int, input().split()))\nballs_counter = Counter(balls)\nfor key , val in balls_counter.items():\n ball_com[key - 1] = cmb(val, 2)\n\ncmb_sum = sum(ball_com)\nfor ball in balls:\n print(cmb_sum - ball_com[ball - 1] + cmb(balls_counter[ball] - 1, 2))\n'] | ['Wrong Answer', 'Accepted'] | ['s062183685', 's872614963'] | [52164.0, 28436.0] | [728.0, 461.0] | [816, 399] |
p02732 | u983181637 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['from scipy.misc import comb\nfrom collections import defaultdict\nd = defaultdict(lambda: -1)\nn = int(input())\na = [int(x) for x in input().split()]\nans = 0\nfor i in range(len(a)):\n a_ = a.copy()\n b = a_.pop(i)\n if d[str(b)] != -1:\n print(d[str(b)])\n continue\n A = list(set(a_))\n ans = 0\n for j in A:\n ans += comb(a_.count(j), 2, exact=True)\n\n d[str(b)] = ans\n print(ans)\n', 'n = int(input())\na = [int(x) for x in input().split()]\nfrom collections import defaultdict\nd = defaultdict(int)\nfor i in a:\n d[i] += 1\n\ntotal = 0\nfor i in set(a):\n x = d[i]\n total += x*(x-1)/2\n\nfor i in a:\n x = d[i]\n print(int(total-(x*(x-1)/2)))', 'from scipy.misc import comb\nfrom collections import defaultdict\nd = defaultdict(lambda: -1)\nd_ = defaultdict(lambda: -1)\nn = int(input())\na = [int(x) for x in input().split()]\n\nfor i in range(len(a)):\n a_ = a.copy()\n b = a_.pop(i)\n if d[str(b)] != -1:\n print(d[str(b)])\n continue\n A = list(set(a_))\n ans = 0\n for j in A:\n c = a_.count(j)\n if d_[str(c)] != -1:\n ans += d_[str(c)]\n else:\n e = comb(c, 2, exact=True)\n ans += e\n d_[str(c)] = e\n\n d[str(b)] = ans\n print(ans)\n\n\n', 'from scipy.misc import comb\nn = int(input())\na = [int(x) for x in input().split()]\nans = 0\nfor i in range(len(a)):\n a_ = a.copy()\n a_.pop(i)\n A = list(set(a_))\n ans = 0\n for j in A:\n ans += comb(a_.count(j), 2, exact=True)\n\n print(ans)\n\n\n', 'from scipy.misc import comb\nfrom collections import defaultdict\nfrom collections import deque\nd = defaultdict(lambda: -1)\nd_ = defaultdict(lambda: -1)\nn = int(input())\na = deque([int(x) for x in input().split()])\n\nfor i in a:\n a_ = a.copy()\n b = a_.remove(i)\n if d[str(b)] != -1:\n print(d[str(b)])\n continue\n A = list(set(a_))\n ans = 0\n for j in A:\n c = a_.count(j)\n if d_[str(c)] != -1:\n ans += d_[str(c)]\n else:\n e = comb(c, 2, exact=True)\n ans += e\n d_[str(c)] = e\n\n d[str(b)] = ans\n print(ans)\n\n\n', 'from scipy.misc import comb\nfrom collections import defaultdict\nfrom collections import deque\nd = defaultdict(lambda: -1)\nd_ = defaultdict(lambda: -1)\nn = int(input())\na = deque([int(x) for x in input().split()])\n\nfor i in a:\n a_ = a.copy()\n b = a_.remove(i)\n if d[str(b)] != -1:\n print(d[str(b)])\n continue\n A = list(set(a_))\n ans = 0\n for j in A:\n c = a_.count(j)\n if d_[str(c)] != -1:\n ans += d_[str(c)]\n else:\n e = comb(c, 2, exact=True)\n ans += e\n d_[str(c)] = e\n\n d[str(b)] = ans\n print(ans)\n\n\n', 'from scipy.misc import comb\nfrom collections import defaultdict, deque\nd = defaultdict(lambda: -1)\nd_ = defaultdict(lambda: -1)\nn = int(input())\na = deque([int(x) for x in input().split()])\nfor i in a:\n a_ = a.copy()\n a_.remove(i)\n b = i\n if d[str(b)] != -1:\n print(d[str(b)])\n continue\n A = list(set(a_))\n ans = 0\n for j in A:\n c = a_.count(j)\n if d_[str(c)] != -1:\n ans += d_[str(c)]\n else:\n e = comb(c, 2, exact=True)\n ans += e\n d_[str(c)] = e\n\n d[str(b)] = ans\n print(ans)\n\n\n', 'n = int(input())\na = [int(x) for x in input().split()]\nfrom collections import defaultdict\nd = defaultdict(int)\nfor i in a:\n d[i] += 1\n\ntotal = 0\nfor i in set(a):\n x = d[i]\n total += x*(x-1)/2\n\nfor i in a:\n x = d[i]\n print(int(total-((x*(x-1)/2))+((x-1)*(x-2)/2)))'] | ['Time Limit Exceeded', 'Wrong Answer', 'Time Limit Exceeded', 'Time Limit Exceeded', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s044277026', 's135921196', 's165633848', 's608074039', 's774831221', 's890451851', 's891759306', 's216882527'] | [36544.0, 26748.0, 36620.0, 35248.0, 36228.0, 35196.0, 37664.0, 26144.0] | [2109.0, 434.0, 2109.0, 2109.0, 243.0, 214.0, 250.0, 483.0] | [387, 251, 515, 247, 543, 543, 523, 269] |
p02732 | u991269553 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['n = int(input())\na = list(map(int,input().split()))\n\nimport math\n\ndef comb(n, r):\n if n <= 1:\n return 0\n else:\n return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))\n\n\ncount = 0\nkaisuu = []\nsum = 0\nkaisuu = [0 for _ in range(n)]\nfor num in range(1,max(a)+1):\n count = 0\n for i in range(n):\n if a[i] == num:\n count += 1\n \n kaisuu[num] = count\n sum += count + (count - 1)//2\n\n\n\nfor k in range(n):\n ans = sum - kaisuu[a[k]] + 1\n print(ans)\n ', 'import collections\n\n#start = time.time()\n\n\n\nx=int(input())\na=list(map(int,input().split()))\n \nc=collections.Counter(a)\n#print(c)\n\nnum=0\nfor i in c.values():\n num += i*(i-1)/2\n \nfor i in range(x):\n print(int(num-c[a[i]]+1))'] | ['Runtime Error', 'Accepted'] | ['s492176164', 's014758249'] | [26140.0, 26780.0] | [2104.0, 420.0] | [560, 244] |
p02732 | u996731299 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['M=int(input())\nN=list(input().split())\nprint(N)\ncheck=[0,0,0,0,0,0,0,0,0,0]\nfor i in range(M):\n check[int(N[i])]+=1\nnum=0\nfor i in range(M):\n num+=check[i]*(check[i]-1)//2\nfor i in range(M):\n print(num-(check[int(N[i])]-1))', 'M=int(input())\nN=list(input().split())\nprint(N)\ncheck=[0]*M\nfor i in range(M):\n check[int(N[i])-1]+=1\nnum=0\nfor i in range(M):\n num+=check[i]*(check[i]-1)//2\nfor i in range(M):\n print(num-(check[int(N[i])-1]-1))', 'M=int(input())\nN=list(input().split())\ncheck=[0]*M\nfor i in range(M):\n check[int(N[i])-1]+=1\nnum=0\nfor i in range(M):\n num+=check[i]*(check[i]-1)//2\nfor i in range(M):\n \n print(num-(check[int(N[i])-1]-1))\n #else:\n # print(num-1)'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s387044660', 's506182413', 's838893023'] | [22496.0, 24316.0, 20992.0] | [96.0, 428.0, 417.0] | [232, 220, 275] |
p02732 | u999503965 | 2,000 | 1,048,576 | We have N balls. The i-th ball has an integer A_i written on it. For each k=1, 2, ..., N, solve the following problem and print the answer. * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal. | ['n=int(input())\nl=list(map(int,input().split()))\n\nd = [0]*n\nans=0\n \nfor a in l:\n d[a-1] += 1\n \nfor a in d:\n ans+=a*(a-1)//2\n \nprint(ans)\n ', '# -*- coding: utf-8 -*-\n"""\nCreated on Mon Sep 7 22:04:16 2020\n\n@author: liang\n"""\n\nN = int(input())\nA = [int(x) for x in input().split()]\nd = [0]*N\n\nfor a in A:\n d[a-1] += 1\n#print(d)\nscore = 0\nfor a in d:\n score += a*(a-1)//2\n#print(score)\nfor a in A:\n print(score - d[a-1] + 1)\n'] | ['Wrong Answer', 'Accepted'] | ['s609479251', 's092661823'] | [32316.0, 32316.0] | [118.0, 210.0] | [144, 292] |
p02733 | u002539468 | 2,000 | 1,048,576 | We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`. We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar. How many times do we need to cut the bar so that every block after the cuts has K or less white squares? | ['import numpy as np\n\nH, W, K = map(int, input().split())\nS = []\nfor _ in range(H):\n S.append(list(map(int, list(input()))))\nS = np.array(S)\n\nif S.sum() <= K:\n print(0)\n exit(0)\n\ndef satisfy(left, right, S2):\n global K\n for row in S2:\n # if row[left:(right + 1)].sum() > K:\n # return False\n pass\n return True\n\n# ex. horizons = [0, 0, 1, 0, 0, 1]\ndef greedy(horizons):\n global W, S\n answer = sum(horizons)\n left = 0\n right = 0\n \n \n # ex.\n # S = [[1, 1, 1, 0, 0],\n # [1, 0, 0, 0, 1],\n # [0, 0, 1, 1, 1]]\n \n # S2 = [[2, 1, 1, 0, 0],\n # [0, 0, 1, 1, 1]]\n \n top = 0\n bottom = 0\n S2 = []\n for h in horizons:\n if h == 1:\n S2.append(S[:][top:(bottom + 1)].sum(axis=0))\n top = bottom + 1\n bottom += 1\n S2.append(S[:][top:].sum(axis=0))\n while right <= W - 1:\n if not satisfy(left, right, S2):\n \n if left == right:\n return -1\n left = right\n answer += 1\n else:\n right += 1\n return answer\n\nanswer = (H - 1) * (W - 1)\n\n# result = greedy([0, 1, 0])\n\nfor i in range(0, 2 ** (H - 1)):\n horizons = list(map(int, list(bin(i)[2:].zfill(H - 1))))\n result = greedy(horizons)\n if result > 0 and result < answer:\n answer = result\n\nprint(answer)\n', 'H, W, K = map(int, input().split())\nS = []\nfor _ in range(H):\n S.append(list(map(int, list(input()))))\n\nif sum(map(sum, S)) <= K:\n print(0)\n exit(0)\n\ndef satisfy(left, right, horizons):\n global K, S\n top = 0\n for idx, h in enumerate(horizons):\n if h == 1:\n bottom = idx\n \n # row[left:(right + 1)]), S[top:(bottom + 1)]))\n total = 0\n \n if total > K:\n return False\n top = bottom + 1\n row[left:(right + 1)]), S[top:]))\n total = 0\n \n if total > K:\n return False\n return True\n\n# ex. horizons = [0, 0, 1, 0, 0, 1]\ndef greedy(horizons):\n answer = sum(horizons)\n left = 0\n right = 0\n \n \n while right <= W - 1:\n if not satisfy(left, right, horizons):\n if left == right:\n return -1\n left = right\n answer += 1\n else:\n right += 1\n return answer\n\nanswer = (H - 1) * (W - 1)\n\n# result = greedy([0, 1, 0])\n\nfor i in range(0, 2 ** (H - 1)):\n horizons = list(map(int, list(bin(i)[2:].zfill(H - 1))))\n result = greedy(horizons)\n if result > 0 and result < answer:\n answer = result\n\nprint(answer)\n', "import numpy as np\n\ndef main():\n H, W, K = map(int, input().split())\n S = []\n for _ in range(H):\n S.append(list(map(int, list(input()))))\n S = np.array(S)\n if S.sum() <= K:\n print(0)\n exit(0)\n answer = float('INF')\n for i in range(0, 2 ** (H - 1)):\n horizons = list(map(int, list(bin(i)[2:].zfill(H - 1))))\n result = greedy(W, S, K, horizons, answer)\n answer = min(answer, result)\n print(answer)\n\n# ex. horizons = [0, 0, 1, 0, 0, 1]\ndef greedy(W, S, K, horizons, current_answer):\n answer = sum(horizons)\n # ex.\n # S = [[1, 1, 1, 0, 0],\n # [1, 0, 0, 0, 1],\n # [0, 0, 1, 1, 1]]\n \n # S2 = [[2, 1, 1, 0, 0],\n # [0, 0, 1, 1, 1]]\n \n top = 0\n bottom = 0\n S2 = []\n for h in horizons:\n if h == 1:\n S2.append(S[:][top:(bottom + 1)].sum(axis=0).tolist())\n top = bottom + 1\n bottom += 1\n S2.append(S[:][top:].sum(axis=0).tolist())\n \n h = len(S2)\n partial_sums = [0] * h\n for right in range(W):\n current = [0] * h\n for idx in range(h):\n current[idx] = S2[idx][right]\n partial_sums[idx] += S2[idx][right]\n \n if max(current) > K:\n return float('INF')\n \n if max(partial_sums) > K:\n answer += 1\n if answer >= current_answer:\n return float('INF')\n partial_sums = current\n return answer\n\nif __name__ == '__main__':\n main()\n"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s592319545', 's698639883', 's104391330'] | [13416.0, 3188.0, 12564.0] | [324.0, 649.0, 1227.0] | [1630, 1536, 1748] |
p02733 | u033183216 | 2,000 | 1,048,576 | We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`. We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar. How many times do we need to cut the bar so that every block after the cuts has K or less white squares? | ["\nimport sys\n\nans = sys.maxsize\nH, W, K = map(int, input().split())\ns = [input() for _ in range(H)]\n\nfor h in range(1 << (H - 1)):\n g = 0\n ids = [-1 for _ in range(H)]\n for i in range(H):\n ids[i] = g\n if (h >> i) & 1:\n g += 1\n\n g += 1\n c = [[[0] * W] for _ in range(g)]\n for i in range(H):\n for j in range(W):\n c[ids[i]][j] = c[ids[i]][j] + (s[i][j] == '1')\n\n num = g - 1\n now = [0 for _ in range(g)]\n\n\n def add(j):\n for i in range(g):\n now[i] += c[i][j]\n\n for i in range(g):\n if now[i] > K:\n return False\n\n return True\n\n\n if num >= ans:\n continue\n\n for j in range(W):\n if not add(j):\n num += 1\n if num >= ans:\n continue\n now = [0 for _ in range(g)]\n if not add(j):\n num = sys.maxsize\n break\n\n ans = min(ans, num)\n\nprint(ans)\n", "\nimport sys\n\nans = sys.maxsize\nH, W, K = map(int, input().split())\ns = [input() for _ in range(H)]\n\nfor h in range(1 << (H - 1)):\n g = 0\n ids = [-1 for _ in range(H)]\n for i in range(H):\n ids[i] = g\n if (h >> i) & 1:\n g += 1\n\n g += 1\n num = g - 1\n\n if num >= ans:\n continue\n\n c = [[0] * W for _ in range(g)]\n for i in range(H):\n for j in range(W):\n c[ids[i]][j] = c[ids[i]][j] + (s[i][j] == '1')\n\n now = [0 for _ in range(g)]\n\n\n def add(j):\n for i in range(g):\n now[i] += c[i][j]\n\n for i in range(g):\n if now[i] > K:\n return False\n\n return True\n\n\n for j in range(W):\n if not add(j):\n num += 1\n if num >= ans:\n continue\n now = [0 for _ in range(g)]\n if not add(j):\n num = sys.maxsize\n break\n\n ans = min(ans, num)\n\nprint(ans)\n"] | ['Runtime Error', 'Accepted'] | ['s691230201', 's064023186'] | [3064.0, 3188.0] | [18.0, 2000.0] | [1016, 1015] |
p02733 | u036104576 | 2,000 | 1,048,576 | We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`. We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar. How many times do we need to cut the bar so that every block after the cuts has K or less white squares? | ['import sys\nimport itertools\n# import numpy as np\nimport time\nimport math\nfrom heapq import heappop, heappush\nfrom collections import defaultdict\nfrom collections import Counter\nfrom collections import deque\nfrom itertools import permutations\nsys.setrecursionlimit(10 ** 7)\n \nINF = 10 ** 18\nMOD = 10 ** 9 + 7\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\n\n# map(int, input().split())\nH, W, K = map(int, input().split())\nS = [input() for _ in range(H)]\nacc = [[0] * (W + 1) for _ in range(H)]\nfor i in range(H):\n for j in range(1, W + 1):\n acc[i][j] = acc[i][j - 1] + int(S[i][j - 1])\n\n\nans = INF\nfor bit in range(1 << (H - 1)):\n base = 0\n vertical = []\n for i in range(H - 1):\n if bit & 1 << i > 0:\n vertical.append((base, i))\n base = i + 1\n vertical.append((base, H - 1))\n\n tmp_ans = len(vertical) - 1\n prev = 0\n j = 1\n valid = False\n while j <= W:\n ok = True\n for v in vertical:\n now = 0\n for i in range(v[0], v[1] + 1):\n now += acc[i][j] - acc[i][prev]\n if now > K:\n ok = False\n if ok:\n valid = True\n else:\n if valid:\n prev = j\n tmp_ans += 1\n valid = False\n else:\n break\n j += 1\n if valid:\n ans = min(tmp_ans, ans)\nprint(ans)', 'import sys\nimport itertools\n# import numpy as np\nimport time\nimport math\nfrom heapq import heappop, heappush\nfrom collections import defaultdict\nfrom collections import Counter\nfrom collections import deque\nfrom itertools import permutations\nsys.setrecursionlimit(10 ** 7)\n \nINF = 10 ** 18\nMOD = 10 ** 9 + 7\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\n\n# map(int, input().split())\nH, W, K = map(int, input().split())\nS = [input() for _ in range(H)]\nacc = [[0] * (W + 1) for _ in range(H)]\nfor i in range(H):\n for j in range(1, W + 1):\n acc[i][j] = acc[i][j - 1] + int(S[i][j - 1])\n\n\nans = INF\nfor bit in range(1 << (H - 1)):\n base = 0\n vertical = []\n for i in range(H - 1):\n if bit & 1 << i > 0:\n vertical.append((base, i))\n base = i + 1\n vertical.append((base, H - 1))\n\n tmp_ans = len(vertical) - 1\n prev = 0\n j = 1\n valid = False\n while j <= W:\n ok = True\n for v in vertical:\n now = 0\n for i in range(v[0], v[1] + 1):\n now += acc[i][j] - acc[i][prev]\n if now > K:\n ok = False\n if ok:\n valid = True\n else:\n if valid:\n prev = j - 1\n tmp_ans += 1\n valid = False\n continue\n else:\n break\n j += 1\n if valid:\n ans = min(tmp_ans, ans)\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s651627475', 's806928800'] | [9536.0, 9672.0] | [1973.0, 1993.0] | [1453, 1482] |
p02733 | u078181689 | 2,000 | 1,048,576 | We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`. We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar. How many times do we need to cut the bar so that every block after the cuts has K or less white squares? | ['h,w,k = list(map(int,input().split()))\narr = [[int(i) for i in input()] for _ in range(h)]\n\nfrom itertools import product\nans = [0]*(2**(h-1))\n\nfor idx,cond in enumerate(product((True,False),repeat=h-1)):\n div = sum(cond)\n spl = [arr[0][:]]\n for i in range(h-1):\n if h_cond[i]:\n spl.append(arr[i+1][:])\n else:\n spl[-1] = [spl[-1][j] + arr[i+1][j] for j in range(w)]\n num = len(spl)\n cnt = [0]*num\n \n for v in range(w):\n tmp = [spl[i][v] for i in range(num)]\n if max(tmp) > k:\n break\n if max([cnt[i] + tmp[i] for i in range(num)]) > k:\n div += 1\n cnt = tmp[:]\n else:\n cnt = [cnt[i] + tmp[i] for i in range(num)]\n else: \n ans = min(ans,div)\n \nprint(min(ans))', 'h,w,k = list(map(int,input().split())); arr = [[int(i) for i in input()] for _ in range(h)]\n\nfrom itertools import product\nans = 2000\n\nfor cond in product([True,False],repeat=(h-1)):\n cut = sum(cond)\n splits = [arr[0][:]]\n for i in range(1,h):\n if cond[i-1]:\n splits.append(arr[i][:])\n else:\n splits[-1] = [splits[-1][j]+arr[i][j] for j in range(w)]\n \n check = [max(i) for i in splits]\n if max(check) > k:\n break\n count = [i[0] for i in splits]\n \n div = cut\n for j in range(1,w):\n addarr = [count[i]+splits[i][j] for i in range(cut+1)]\n if max(addarr) > k:\n div += 1\n count = [splits[i][j] for i in range(cut+1)]\n else:\n count = addarr[:]\n ans = min(ans,div)\n \nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s711904667', 's318462096'] | [3188.0, 3316.0] | [19.0, 1269.0] | [810, 808] |
p02733 | u106778233 | 2,000 | 1,048,576 | We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`. We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar. How many times do we need to cut the bar so that every block after the cuts has K or less white squares? | ['import itertools\n\nH, W, K = map(int, input().split())\nS = []\nfor _ in range(H):\n S.append([int(s) for s in input()])\n \n\nans = 2000\nfor t in itertools.product([0, 1], repeat=H - 1):\n cnt = t.count(1)\n #print(cnt)\n lst = [[s for s in S[0]]]\n for h in range(H - 1):\n \n #print(lst\n \n if t[h]:\n lst.append(S[h + 1])\n \n else:\n lst[-1] = [lst[-1][i] + S[h + 1][i] for i in range(W)]\n \n #print(lst)\n L = len(lst)\n print(L)\n sum_lst = [0] * L\n \n for w in range(W):\n if max(lst[i][w] for i in range(L)) > K:\n break\n \n tmp = [sum_lst[i] + lst[i][w] for i in range(L)]\n if max(tmp) > K:\n cnt += 1 \n sum_lst = [lst[i][w] for i in range(L)]\n else:\n sum_lst = tmp \n else:\n ans = min(ans, cnt)\n \nprint(ans)\n', 'import itertools\n\nH, W, K = map(int, input().split())\nS = []\nfor _ in range(H):\n S.append([int(s) for s in input()])\n \n\nans = 2000\nfor t in itertools.product([0, 1], repeat=H - 1):\n cnt = t.count(1)\n #print(cnt)\n lst = [[s for s in S[0]]]\n for h in range(H - 1):\n \n #print(lst\n \n if t[h]:\n lst.append(S[h + 1])\n \n else:\n lst[-1] = [lst[-1][i] + S[h + 1][i] for i in range(W)]\n \n #print(lst)\n L = len(lst)\n #print(L)\n sum_lst = [0] * L\n \n for w in range(W):\n if max(lst[i][w] for i in range(L)) > K:\n break\n \n tmp = [sum_lst[i] + lst[i][w] for i in range(L)]\n if max(tmp) > K:\n cnt += 1 \n sum_lst = [lst[i][w] for i in range(L)]\n else:\n sum_lst = tmp \n else:\n ans = min(ans, cnt)\n \nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s813063128', 's499852753'] | [3316.0, 3188.0] | [1884.0, 1873.0] | [1521, 1522] |
p02733 | u111473084 | 2,000 | 1,048,576 | We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`. We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar. How many times do we need to cut the bar so that every block after the cuts has K or less white squares? | ["def main():\n import sys\n sys.setrecursionlimit(10**9)\n input = sys.stdin.readline\n INF = 10**9\n\n H, W, K = map(int, input().split())\n chocolate = [ input()[:-1] for _ in range(H) ]\n \n loop_H = range(H)\n loop_W = range(W)\n white_chocolate = [ [0]*(W+1) for _ in range(10) ]\n min_cut = INF-1\n for div in range(1 << (H-1)):\n \n group = [[]]\n group_number = 0\n for i in loop_H:\n group[group_number].append(i)\n if div >> i & 1:\n group.append([])\n group_number += 1\n \n for i in loop_W:\n for g in range(group_number+1):\n white_chocolate[g][i] = 0\n for j in group[g]:\n if chocolate[j][i] == '1':\n white_chocolate[g][i] += 1\n \n cut = group_number\n zeros = [0] * len(group_number+1)\n now = zeros.copy()\n for w in loop_W:\n for g in range(len(white_chocolate)):\n if white_chocolate[g][w] > K:\n cut = INF\n break\n else:\n now[g] += white_chocolate[g][w]\n if now[g] + white_chocolate[g][w+1] > K:\n cut += 1\n now = zeros.copy()\n break\n if cut == INF:\n break\n if cut < min_cut:\n min_cut = cut\n print(min_cut)\n\nmain()", "def main():\n import sys\n sys.setrecursionlimit(10**9)\n input = sys.stdin.readline\n INF = 10**9\n\n H, W, K = map(int, input().split())\n chocolate = [ input()[:-1] for _ in range(H) ]\n \n loop_H = range(H)\n loop_W = range(W)\n min_cut = INF-1\n for div in range(1 << (H-1)):\n \n group = [[]]\n group_number = 0\n for i in loop_H:\n group[group_number].append(i)\n if div >> i & 1:\n group.append([])\n group_number += 1\n \n cut = group_number\n zeros = [0] * (group_number + 1)\n now = zeros.copy()\n for w in loop_W:\n for g in range(len(group)):\n cnt = 0\n for i in group[g]:\n if chocolate[i][w] == '1':\n cnt += 1\n if cnt > K:\n cut = INF\n break\n if now[g] + cnt > K:\n cut += 1\n now = zeros.copy()\n break\n now[g] += cnt\n if cut == INF:\n break\n if cut < min_cut:\n min_cut = cut\n print(min_cut)\n\nmain()", "def main():\n import sys\n sys.setrecursionlimit(10**9)\n input = sys.stdin.readline\n INF = 10**9\n\n H, W, K = map(int, input().split())\n chocolate = [ input()[:-1] for _ in range(H) ]\n \n loop_H = range(H)\n loop_W = range(W)\n white_chocolate = [ [0]*(W+1) for _ in range(group_number+1) ]\n min_cut = INF-1\n for div in range(1 << (H-1)):\n \n group = [[]]\n group_number = 0\n for i in loop_H:\n group[group_number].append(i)\n if div >> i & 1:\n group.append([])\n group_number += 1\n \n for i in loop_W:\n for g in range(group_number+1):\n white_chocolate[g][i] = 0\n for j in group[g]:\n if chocolate[j][i] == '1':\n white_chocolate[g][i] += 1\n \n cut = group_number\n zeros = [0] * len(white_chocolate)\n now = zeros.copy()\n for w in loop_W:\n for g in range(len(white_chocolate)):\n if white_chocolate[g][w] > K:\n cut = INF\n break\n else:\n now[g] += white_chocolate[g][w]\n if now[g] + white_chocolate[g][w+1] > K:\n cut += 1\n now = zeros.copy()\n break\n if cut == INF:\n break\n if cut < min_cut:\n min_cut = cut\n print(min_cut)\n\nmain()", "def main():\n import sys\n sys.setrecursionlimit(10**9)\n input = sys.stdin.readline\n INF = 10**9\n\n H, W, K = map(int, input().split())\n chocolate = [ input() for _ in range(H) ]\n \n loop_H = range(H)\n min_cut = INF-1\n for div in range(1 << (H-1)):\n \n group = [[]]\n group_number = 0\n for i in loop_H:\n group[group_number].append(i)\n if div >> i & 1:\n group.append([])\n group_number += 1\n \n cut = group_number\n cnt = [0] * len(group)\n w = 0\n while w < W:\n now = [0] * len(group)\n for g in range(len(group)):\n for i in group[g]:\n if chocolate[i][w] == '1':\n now[g] += 1\n if now[g] > K:\n cut = INF\n break\n if cnt[g] + now[g] > K:\n cut += 1\n w -= 1\n cnt = [0] * len(group)\n break\n cnt[g] += now[g]\n if cut >= min_cut:\n break\n w += 1\n if cut < min_cut:\n min_cut = cut\n print(min_cut)\n\nmain()"] | ['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s308028850', 's695971386', 's696456428', 's665571824'] | [3188.0, 3064.0, 3064.0, 3064.0] | [20.0, 1339.0, 18.0, 421.0] | [1561, 1255, 1574, 1278] |
p02733 | u141786930 | 2,000 | 1,048,576 | We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`. We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar. How many times do we need to cut the bar so that every block after the cuts has K or less white squares? | ['\nimport numpy as np\n\nH, W, K = map(int, input().split())\nS = np.zeros((H, W), dtype=np.int64)\n\nans = H+W\n\nfor i in range(H):\n S[i] = list(str(input()))\n\nfor m in range(2**(H-1)):\n wp = np.zeros((H, W), dtype=np.int64)\n wq = np.zeros((H, ), dtype=np.int64)\n wp[0] = S[0]\n cut = 0\n for n in range(H-1):\n if m>>n&1:\n cut += 1\n wp[cut] += S[n+1]\n\n if cut >= ans or np.count_nonzero(wp > K):\n continue\n\n for j in range(W): \n wq += wp[-1,j]\n if np.count_nonzero(wq > K):\n cut += 1\n wq = wp[-1,j]\n ans = min(ans, cut)\n\nprint(ans)\n\n', "\nimport numpy as np\n\nH, W, K = map(int, input().split())\nS = np.zeros((H, W), dtype=np.int64)\n\nans = H+W\n\nfor i in range(H):\n S[i] = list(str(input()))\n\nfor m in range(1<<(H-1)):\n cut = bin(m).count('1')\n if cut >= ans:\n continue\n\n wp = np.zeros((cut+1, W), dtype=np.int64)\n wp[0] = S[0]\n c = 0\n for n in range(H-1):\n if m>>n&1:\n c += 1\n wp[c] += S[n+1]\n\n if np.count_nonzero(wp > K):\n continue\n\n wq = np.zeros((cut+1, ), dtype=np.int64)\n for j in range(W):\n wq += wp[:,j]\n if np.count_nonzero(wq > K):\n cut += 1\n wq = wp[:,j]\n\n ans = min(ans, cut)\n\nprint(ans)\n\n\n"] | ['Wrong Answer', 'Accepted'] | ['s177108494', 's016738149'] | [13660.0, 21264.0] | [191.0, 1247.0] | [643, 695] |
p02733 | u145600939 | 2,000 | 1,048,576 | We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`. We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar. How many times do we need to cut the bar so that every block after the cuts has K or less white squares? | ["h,w,k = map(int,input().split())\nchoco = [list(map(int,list(input()))) for _ in range(h)]\n\nwhite = [[0]*w for _ in range(h)]\nfor i in range(h):\n for j in range(w):\n if i != 0:\n white[i][j] += white[i-1][j]\n if j != 0:\n white[i][j] += white[i][j-1]\n if i != 0 and j != 0:\n white[i][j] -= white[i-1][j-1]\n white[i][j] += choco[i][j]\nans = float('inf')\nfor i in range(2**(h-1)): \n temp = format(i,'b').count('1') \n hw = []\n j = i\n cnt = 0\n while j >0:\n if j&1:\n hw.append(cnt)\n cnt += 1\n j = j >> 1\n hw.append(h-1)\n now = -1\n #if w == 1:\n flag = True\n for l in range(len(hw)):\n if l == 0:\n if white[hw[l]][0] > k:\n flag = False\n break\n else:\n if white[hw[l]][0] - white[hw[l-1]][0] > k:\n flag = False\n break\n if not flag:\n continue\n else:\n ans = min(ans,temp)\n continue\n for j in range(w-1):\n flag = True\n if now == -1:\n for l in range(len(hw)):\n if l == 0:\n if white[hw[l]][j+1] > k:\n flag = False\n break\n else:\n if white[hw[l]][j+1] - white[hw[l-1]][j+1] > k:\n flag = False\n break\n if not flag:\n now = j\n temp += 1\n else:\n for l in range(len(hw)):\n if l == 0:\n if white[hw[l]][j+1] - white[hw[l]][now] > k:\n flag = False\n break\n else:\n if white[hw[l]][j+1] - white[hw[l]][now] - white[hw[l-1]][j+1] + white[hw[l-1]][now]> k:\n flag = False\n break\n if not flag:\n now = j\n temp += 1\n ans = min(ans,temp)\nprint(ans)\n", "h,w,k = map(int,input().split())\nchoco = [list(map(int,list(input()))) for _ in range(h)]\n\nwhite = [[0]*w for _ in range(h)]\nfor i in range(h):\n for j in range(w):\n if i != 0:\n white[i][j] += white[i-1][j]\n if j != 0:\n white[i][j] += white[i][j-1]\n if i != 0 and j != 0:\n white[i][j] -= white[i-1][j-1]\n white[i][j] += choco[i][j]\nans = float('inf')\nfor i in range(2**(h-1)): \n temp = format(i,'b').count('1') \n hw = []\n j = i\n cnt = 0\n while j >0:\n if j&1:\n hw.append(cnt)\n cnt += 1\n j = j >> 1\n hw.append(h-1)\n now = -1\n #if w == 1:\n flag = True\n for l in range(len(hw)):\n if l == 0:\n if white[hw[l]][0] > k:\n flag = False\n break\n else:\n if white[hw[l]][0] - white[hw[l-1]][0] > k:\n flag = False\n break\n if not flag:\n continue\n elif w == 1:\n ans = min(ans,temp)\n continue\n\n for j in range(w-1):\n flag = True\n if now == -1:\n for l in range(len(hw)):\n if l == 0:\n if white[hw[l]][j+1] > k:\n flag = False\n break\n else:\n if white[hw[l]][j+1] - white[hw[l-1]][j+1] > k:\n flag = False\n break\n if not flag:\n now = j\n temp += 1\n else:\n for l in range(len(hw)):\n if l == 0:\n if white[hw[l]][j+1] - white[hw[l]][now] > k:\n flag = False\n break\n else:\n if white[hw[l]][j+1] - white[hw[l]][now] - white[hw[l-1]][j+1] + white[hw[l-1]][now]> k:\n flag = False\n break\n if not flag:\n now = j\n temp += 1\n ans = min(ans,temp)\nprint(ans)\n"] | ['Wrong Answer', 'Accepted'] | ['s621181350', 's358742430'] | [3436.0, 3564.0] | [35.0, 1479.0] | [2101, 2109] |
p02733 | u171255092 | 2,000 | 1,048,576 | We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`. We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar. How many times do we need to cut the bar so that every block after the cuts has K or less white squares? | ['import numpy as np\nimport itertools\n\nH, W, K = map(int, input().split())\nS = np.array([[s for s in input()] for _ in range(H)], dtype=np.int)\n\nans = 2000\nfor t in itertools.product([0, 1], repeat=H - 1):\n cut = t.count(1)\n lst = np.zeros((cut + 1, W), dtype=np.int)\n lst[0] += S[0]\n c = 0\n for h in range(H - 1):\n if t[h]:\n c += 1\n lst[c] += S[h + 1]\n L = len(lst)\n sum_lst = np.zeros(L)\n for w in range(W):\n lst_w = lst[:, w]\n if lst_w.max() > K:\n break\n\n lst_s = sum_lst + lst_w\n if lst_s.max() > K:\n cut += 1\n sum_lst = lst_w\n else:\n sum_lst = lst_s\n else:\n ans = min(ans, cut)\nprint(ans)', 'import itertools\n \nH, W, K = map(int, input().split())\nS = []\nfor _ in range(H):\n S.append(list(map(int, input().split())))\n \nans = 2000\nfor t in itertools.product([0, 1], repeat=H - 1):\n cnt = t.count(1)\n lst = [[s for s in S[0]]]\n for h in range(H - 1):\n if t[h]:\n lst.append(S[h + 1])\n else:\n lst[-1] = [lst[-1][i] + S[h + 1][i] for i in range(W)]\n L = len(lst)\n sum_lst = [0] * L\n for w in range(W):\n if max(lst[i][w] for i in range(L)) > K:\n break\n tmp = [sum_lst[i] + lst[i][w] for i in range(L)]\n if max(tmp) > K:\n cnt += 1\n sum_lst = [lst[i][w] for i in range(L)]\n else:\n sum_lst = tmp\n else:\n ans = min(ans, cnt)\nprint(ans)', 'import numpy as np\nimport itertools\n\nH, W, K = map(int, input().split())\nS = np.array([[int(s) for s in input()] for _ in range(H)])\n\nans = 2000\nfor t in itertools.product([0, 1], repeat=H - 1):\n cut = sum(t)\n lst = np.zeros((cut + 1, W), dtype=np.int)\n lst[0] += S[0]\n c = 0\n for h in range(H - 1):\n if t[h]:\n c += 1\n lst[c] += S[h + 1]\n L = len(lst)\n sum_lst = np.zeros(L)\n for w in range(W):\n lst_w = np.max(lst, axis=0)\n if lst_w[w] > K:\n break\n\n lst_s = sum_lst + lst_w\n if lst_s.max() > K:\n cut += 1\n sum_lst = lst_w\n else:\n sum_lst = lst_s\n else:\n ans = min(ans, cut)\nprint(ans)\n', 'import itertools\n \nH, W, K = map(int, input().split())\nS = []\nfor _ in range(H):\n S.append([int(s) for s in input()])\n \nans = 2000\nfor t in itertools.product([0, 1], repeat=H - 1):\n cnt = t.count(1)\n lst = [[s for s in S[0]]]\n for h in range(H - 1):\n if t[h]:\n lst.append(S[h + 1])\n else:\n lst[-1] = [lst[-1][i] + S[h + 1][i] for i in range(W)]\n L = len(lst)\n sum_lst = [0] * L\n for w in range(W):\n if max(lst[i][w] for i in range(L)) > K:\n break\n tmp = [sum_lst[i] + lst[i][w] for i in range(L)]\n if max(tmp) > K:\n cnt += 1\n sum_lst = [lst[i][w] for i in range(L)]\n else:\n sum_lst = tmp\n else:\n ans = min(ans, cnt)\nprint(ans)'] | ['Time Limit Exceeded', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s101282704', 's108602097', 's823582458', 's793188747'] | [14440.0, 3064.0, 14456.0, 3188.0] | [2108.0, 18.0, 184.0, 1872.0] | [729, 771, 724, 765] |
p02733 | u174878451 | 2,000 | 1,048,576 | We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`. We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar. How many times do we need to cut the bar so that every block after the cuts has K or less white squares? | ['from itertools import combinations, chain\n\nH, W, K = map(int, input().split())\nSss = []\nfor _ in range(H):\n Sss.append(list(map(int, input())))\n\n\ndef h_divide(Sss, div_is):\n result = []\n for s, e in zip(chain([0], div_is), chain(div_is, [len(Sss)])):\n result.append(Sss[s:e])\n return result\n\n\ndef _v_end(Sss, start, K):\n count = 0\n for i in range(start, len(Sss[0])):\n s = sum(map(lambda Ss: Ss[i], Sss))\n if count + s > K:\n return i - 1\n count += s\n return len(Sss[0]) - 1\n\n\ndef v_end(Ssss, start, K):\n result = -1\n for Sss in Ssss:\n end = _v_end(Sss, start, K)\n if end < start:\n return -1\n if result < 0 or result > end:\n result = end\n return result\n\n\ndef v_div_count(Ssss, K):\n start, result = 0, 0\n while True:\n end = v_end(Ssss, start, K)\n if end < 0:\n return -1\n if end == len(Ssss[0][0]) - 1:\n break\n result += 1\n start = end + 1\n return result\n\n\nh_cands = list(range(1, len(Sss)))\nans = -1\nfor n in range(len(h_cands) + 1):\n for comb in combinations(h_cands, n):\n if n >= ans:\n continue\n Ssss = h_divide(Sss, list(comb))\n cnt = v_div_count(Ssss, K)\n if cnt < 0:\n continue\n if ans < 0 or ans > n + cnt:\n ans = n + cnt\nprint(ans)\n', 'from itertools import combinations, chain\n\nH, W, K = map(int, input().split())\nSss = []\nfor _ in range(H):\n Sss.append(list(map(int, input())))\n\n\ndef h_divide(Sss, div_is):\n result = []\n for s, e in zip(chain([0], div_is), chain(div_is, [len(Sss)])):\n result.append(Sss[s:e])\n return result\n\n\ndef _v_end(Sss, start, K):\n count = 0\n for i in range(start, len(Sss[0])):\n s = sum(map(lambda Ss: Ss[i], Sss))\n if count + s > K:\n return i - 1\n count += s\n return len(Sss[0]) - 1\n\n\ndef v_end(Ssss, start, K):\n result = -1\n for Sss in Ssss:\n end = _v_end(Sss, start, K)\n if end < start:\n return -1\n if result < 0 or result > end:\n result = end\n return result\n\n\ndef v_div_count(Ssss, K):\n start, result = 0, 0\n while True:\n end = v_end(Ssss, start, K)\n if end < 0:\n return -1\n if end == len(Ssss[0][0]) - 1:\n break\n result += 1\n start = end + 1\n return result\n\n\nh_cands = list(range(1, len(Sss)))\nans = -1\nfor n in range(len(h_cands) + 1):\n for comb in combinations(h_cands, n):\n if ans > 0 and n >= ans:\n continue\n Ssss = h_divide(Sss, list(comb))\n cnt = v_div_count(Ssss, K)\n if cnt < 0:\n continue\n if ans < 0 or ans > n + cnt:\n ans = n + cnt\nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s019715645', 's632967673'] | [3188.0, 3188.0] | [20.0, 1664.0] | [1385, 1397] |
p02733 | u197922478 | 2,000 | 1,048,576 | We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`. We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar. How many times do we need to cut the bar so that every block after the cuts has K or less white squares? | ['import numpy as np\nfrom itertools import product\n\nH,W,K = map(int, input().split())\nS = np.array(([list(map(int,list(input()))) for _ in range(H)])).T\n\nif sum(sum(s) for s in S)<=K:\n print(0)\nelse:\n answer = (H-1) * (W-1)\n for X in product([False,True], repeat=H-1):\n ans = np.sum(X)\n if ans >= answer:\n continue\n M = [[0]]\n for i, x in enumerate(X):\n if x:\n M.append([])\n M[-1].append(i+1)\n D = np.array([0]*len(M))\n for s in S:\n D[:] += [sum(s[i] for i in m) for m in M]\n if any(d > K for d in D):\n ans += 1\n if ans >= answer:\n break\n D[:] = [sum(s[i] for i in m) for m in M]\n if any(d > K for d in D):\n ans = answer + 1\n break\n\n answer = min(answer,ans)\n\n print(answer', 'import numpy as np\nfrom itertools import product\n\nH,W,K = map(int, input().split())\nS = np.array([list(map(int,list(input()))) for _ in range(H)]).T\n"""\nH,W,K = 3,5,2\n\nS = [[1,1,1,0,0],\n [1,0,0,0,1],\n [0,0,1,1,1]]\n"""\n\n\nS = np.array(S).T\n\nif np.sum(S)<=K:\n print(0)\nelse:\n answer = H * W\n for X in product([False,True], repeat=H-1):\n ans = np.sum(X)\n #print(ans)\n M = [[0]]\n for i, x in enumerate(X):\n if x:\n M.append([])\n M[-1].append(i+1)\n #print(M)\n D = [0]*len(M)\n #print(D)\n for s in S:\n for k, m in enumerate(M):\n D[k] += np.sum(s[i] for i in m)\n #print("D",D)\n if any(d > K for d in D):\n ans += 1\n #print("ans",ans)\n D[:] = [np.sum(s[i] for i in m) for m in M]\n \n if answer > ans:\n answer = ans\n\n print(min(answer,ans))', 'import numpy as np\nfrom itertools import product\n\nH,W,K = map(int, input().split())\nS = np.array(([list(map(int,list(input()))) for _ in range(H)])).T\nprint(S)\n\nif np.sum(S)<=K:\n print(0)\nelse:\n answer = H * W\n for X in product([False,True], repeat=H-1):\n ans = np.sum(X)\n M = [[0]]\n for i, x in enumerate(X):\n if x:\n M.append([])\n M[-1].append(i+1)\n #print(M)\n D = np.zeros(len(M))\n #print(D)\n for s in S:\n D[:] += [np.sum(s[i] for i in m) for m in M]\n if any(d > K for d in D):\n ans += 1\n #print("ans",ans)\n D[:] = [np.sum(s[i] for i in m) for m in M]\n \n if answer > ans:\n answer = ans\n\n print(min(answer,ans))', "\ndef main():\n from itertools import product\n\n H,W,K = map(int, input().split())\n S = [list(input()) for _ in range(H)]\n \n i = 0\n while i < len(S):\n if '1' in S[i]:\n i += 1\n else:\n del S[i]\n H = len(S)\n \n S = [[int(s[i]) for s in S] for i in range(W)]\n\n if sum(sum(s) for s in S)<=K:\n print(0)\n else:\n answer = (H-1) * (W-1)\n for X in product([False,True], repeat=H-1):\n ans = np.sum(X)\n if ans >= answer:\n continue\n M = [[0]]\n for i, x in enumerate(X):\n if x:\n M.append([])\n M[-1].append(i+1)\n D = [0]*len(M)\n for s in S:\n for k, m in enumerate(M):\n D[k] += sum(s[i] for i in m)\n if any(d > K for d in D):\n ans += 1\n if ans >= answer:\n break\n for k, m in enumerate(M):\n D[k] = sum(s[i] for i in m)\n \n if any(d > K for d in D):\n ans = answer + 1\n break\n\n answer = min(answer,ans)\n\n print(answer)\n\nmain()", 'import numpy as np\nfrom itertools import product\n\nH,W,K = map(int, input().split())\nS = np.array(([list(map(int,list(input()))) for _ in range(H)])).T\n\nif np.sum(S)<=K:\n print(0)\nelse:\n answer = H * W\n for X in product([False,True], repeat=H-1):\n ans = np.sum(X)\n M = [[0]]\n for i, x in enumerate(X):\n if x:\n M.append([])\n M[-1].append(i+1)\n D = [0]*len(M)\n for s in S:\n D[:] += [sum(s[i] for i in m) for m in M]\n if any(d > K for d in D):\n ans += 1\n D[:] = [sum(s[i] for i in m) for m in M]\n \n if answer > ans:\n answer = ans\n\n print(min(answer,ans))', 'import numpy as np\nfrom itertools import product\n\nH,W,K = map(int, input().split())\nS = np.array(([list(map(int,list(input()))) for _ in range(H)])).T\n\nif np.sum(S)<=K:\n print(0)\nelse:\n answer = H * W\n D = []\n for X in product([False,True], repeat=H-1):\n ans = np.sum(X)\n if ans > answer:\n continue\n M = [[0]]\n for i, x in enumerate(X):\n if x:\n M.append([])\n M[-1].append(i+1)\n D = [0]*len(M)\n for s in S:\n D[:] += [sum(s[i] for i in m) for m in M]\n print(D)\n if any(d > K for d in D):\n ans += 1\n D[:] = [sum(s[i] for i in m) for m in M]\n\n if answer > ans:\n answer = ans\n\n print(min(answer,ans))', 'import numpy as np\nfrom itertools import product\n\nH,W,K = map(int, input().split())\nS = np.array(([list(map(int,list(input()))) for _ in range(H)])).T\n\nif np.sum(S)<=K:\n print(0)\nelse:\n answer = H * W\n for X in product([False,True], repeat=H-1):\n ans = np.sum(X)\n if ans >= answer:\n continue\n M = [[0]]\n for i, x in enumerate(X):\n if x:\n M.append([])\n M[-1].append(i+1)\n D = np.zeros(len(M))\n for s in S:\n D[:] += [sum(s[i] for i in m) for m in M]\n print(D)\n if any(d > K for d in D):\n ans += 1\n if ans >= answer:\n break\n D[:] = [sum(s[i] for i in m) for m in M]\n\n if answer > ans:\n answer = ans\n\n print(min(answer,ans))', "\ndef main():\n from itertools import product\n\n H,W,K = map(int, input().split())\n S = [list(input()) for _ in range(H)]\n \n i = 0\n while i < len(S):\n if '1' in S[i]:\n i += 1\n else:\n del S[i]\n H = len(S)\n \n S = [[int(s[i]) for s in S] for i in range(W)]\n\n if sum(sum(s) for s in S)<=K:\n print(0)\n else:\n answer = (H-1) * (W-1)\n for X in product([False,True], repeat=H-1):\n ans = np.sum(X)\n if ans >= answer:\n continue\n M = [[0]]\n for i, x in enumerate(X):\n if x:\n M.append([])\n M[-1].append(i+1)\n D = np.array([0]*len(M))\n for s in S:\n D[:] += [sum(s[i] for i in m) for m in M]\n if any(d > K for d in D):\n ans += 1\n if ans >= answer:\n break\n D[:] = [sum(s[i] for i in m) for m in M]\n if any(d > K for d in D):\n ans = answer + 1\n break\n\n answer = min(answer,ans)\n\n print(answer)\n\nmain()", '\ndef main():\n from itertools import product\n import numpy as np\n\n H,W,K = map(int, input().split())\n S = (np.array([list(map(int,list(input()))) for _ in range(H)]).T).tolist()\n\n if sum(sum(s) for s in S)<=K:\n print(0)\n else:\n answer = (H-1) * (W-1)\n for X in product([False,True], repeat=H-1):\n ans = np.sum(X)\n if ans >= answer:\n continue\n M = [[0]]\n for i, x in enumerate(X):\n if x:\n M.append([])\n M[-1].append(i+1)\n D = [0]*len(M)\n for s in S:\n for k, m in enumerate(M):\n D[k] += sum(s[i] for i in m)\n if any(d > K for d in D):\n ans += 1\n if ans >= answer:\n break\n for k, m in enumerate(M):\n D[k] = sum(s[i] for i in m)\n \n if any(d > K for d in D):\n ans = answer + 1\n break\n\n answer = min(answer,ans)\n\n print(answer)\n\nmain()'] | ['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s140965667', 's197223049', 's249167465', 's416023566', 's633040587', 's638429428', 's703260567', 's757941909', 's726923323'] | [3064.0, 12680.0, 14380.0, 3316.0, 14732.0, 16604.0, 14684.0, 3316.0, 12496.0] | [17.0, 352.0, 2112.0, 21.0, 2108.0, 2108.0, 2108.0, 21.0, 589.0] | [920, 1097, 916, 1274, 720, 774, 830, 1193, 1152] |
p02733 | u268554510 | 2,000 | 1,048,576 | We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`. We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar. How many times do we need to cut the bar so that every block after the cuts has K or less white squares? | ['H,W,K = map(int,input().split())\nimport numpy as np\nfrom collections import deque\nans = 10000\nS = np.array([list(map(int,list(input()))) for _ in range(H)])\ncum = [[0]*W for _ in range(H+1)]\nfor j in range(W):\n for i in range(1,H+1):\n cum[i][j] = cum[i-1][j]+S[i-1][j]\n \ncum = np.array(cum)\nfor i in range(2**(H-1)):\n q = deque([0])\n for h in range(H):\n if (i>>h)&1:\n q.append(h+1)\n q.append(H)\n p = deque()\n judge = False\n for a in range(len(q)-1):\n x = cum[q[a+1]]-cum[q[a]]\n if (x>K).any():\n judge = True\n break\n else:\n p.append(x)\n\n if judge:\n continue\n \n\n \nprint(ans)', 'H,W,K = map(int,input().split())\nimport numpy as np\nfrom collections import deque\nans = 10000\nS = np.array([list(map(int,list(input()))) for _ in range(H)])\ncum = [[0]*W for _ in range(H+1)]\nfor j in range(W):\n for i in range(1,H+1):\n cum[i][j] = cum[i-1][j]+S[i-1][j]\n \ncum = np.array(cum)\nfor i in range(2**(H-1)):\n q = deque([0])\n for h in range(H):\n if (i>>h)&1:\n q.append(h+1)\n q.append(H)\n p = deque()\n judge = False\n for a in range(len(q)-1):\n x = cum[q[a+1]]-cum[q[a]]\n if (x>K).any():\n judge = True\n break\n else:\n p.append(x)\n\n if judge:\n continue\n \n t_a = len(q)-2\n n = len(p)\n l = [0]*n\n for w in range(W):\n for x,a in enumerate(p):\n continue\n ans = min(ans,t_a)\n \nprint(ans)', 'H,W,K = map(int,input().split())\nimport numpy as np\nfrom collections import deque\nans = 10000\nS = np.array([list(map(int,list(input()))) for _ in range(H)])\ncum = [[0]*W for _ in range(H+1)]\nfor j in range(W):\n for i in range(1,H+1):\n cum[i][j] = cum[i-1][j]+S[i-1][j]\n \ncum = np.array(cum)\nfor i in range(2**(H-1)):\n q = deque([0])\n for h in range(H):\n if (i>>h)&1:\n q.append(h+1)\n q.append(H)\n p = deque()\n judge = False\n for a in range(len(q)-1):\n x = cum[q[a+1]]-cum[q[a]]\n if (x>K).any():\n judge = True\n break\n else:\n p.append(x)\n\n if judge:\n continue\n \n t_a = len(q)-2\n n = len(p)\n l = [0]*n\n for w in range(W):\n for x,a in enumerate(p):\n y = l[x]+a[w]\n if y>K:\n t_a+=1\n l = [0]*n\n for z,b in enumerate(p):\n l[z] = b[w]\n break\n ans = min(ans,t_a)\n \nprint(ans)', 'H,W,K = map(int,input().split())\nimport numpy as np\nfrom collections import deque\nans = 10000\nS = np.array([list(map(int,list(input()))) for _ in range(H)])\ncum = [[0]*W for _ in range(H+1)]\nfor j in range(W):\n for i in range(1,H+1):\n cum[i][j] = cum[i-1][j]+S[i-1][j]\n \ncum = np.array(cum)\nfor i in range(2**(H-1)):\n q = deque([0])\n for h in range(H):\n if (i>>h)&1:\n q.append(h+1)\n q.append(H)\n q = list(q)\n p = deque()\n judge = False\n for a in range(len(q)-1):\n x = cum[q[a+1]]-cum[q[a]]\n if (x>K).any():\n judge = True\n break\n else:\n p.append(list(x))\n\n if judge:\n continue\n p = list(p)\n t_a = len(q)-2\n n = len(p)\n l = [0]*n\n for w in range(W):\n for x,a in enumerate(p):\n y = l[x]\n if y>K:\n t_a+=1\n l = [0]*n\n for z,b in enumerate(p):\n l[z] = b[w]\n break\n else:\n l[x]=y\n ans = min(ans,t_a)\n \nprint(ans)', 'H,W,K = map(int,input().split())\nimport numpy as np\nfrom collections import deque\nans = 10000\nS = np.array([list(map(int,list(input()))) for _ in range(H)])\ncum = [[0]*W for _ in range(H+1)]\nfor j in range(W):\n for i in range(1,H+1):\n cum[i][j] = cum[i-1][j]+S[i-1][j]\n \ncum = np.array(cum)\nfor i in range(2**(H-1)):\n q = deque([0])\n for h in range(H):\n if (i>>h)&1:\n q.append(h+1)\n q.append(H)\n p = deque()\n judge = False\n for a in range(len(q)-1):\n x = cum[q[a+1]]-cum[q[a]]\n if (x>K).any():\n judge = True\n break\n else:\n p.append(x)\n\n if judge:\n continue\n \n t_a = len(q)-2\n n = len(p)\n l = [0]*n\n for w in range(W):\n for x,a in enumerate(p):\n if l[x]>K:\n t_a+=1\n l = [0]*n\n for z,b in enumerate(p):\n l[z] = b[w]\n break\n ans = min(ans,t_a)\n \nprint(ans)', 'def main()\n H,W,K = map(int,input().split())\n from collections import deque\n ans = 10000\n S = [list(map(int,list(input()))) for _ in range(H)]\n cum = [[0]*W for _ in range(H+1)]\n for j in range(W):\n for i in range(1,H+1):\n cum[i][j] = cum[i-1][j]+S[i-1][j]\n\n for i in range(2**(H-1)):\n q = deque([0])\n for h in range(H):\n if (i>>h)&1:\n q.append(h+1)\n q.append(H)\n q = list(q)\n p = deque()\n judge = False\n for a in range(len(q)-1):\n x = [x-y for x in cum[q[a+1]] for y in cum[q[a]]]\n for j in x:\n if j>K:\n judge = True\n break\n if judge:\n break\n else:\n p.append(list(x))\n\n if judge:\n continue\n p = list(p)\n t_a = len(q)-2\n n = len(p)\n l = [0]*n\n for w in range(W):\n for x,a in enumerate(p):\n y = l[x]+a[w]\n if y>K:\n t_a+=1\n l = [0]*n\n for z,b in enumerate(p):\n l[z] = b[w]\n break\n else:\n l[x]=y\n ans = min(ans,t_a)\n\n print(ans)\n \nmain()', 'H,W,K = map(int,input().split())\nimport numpy as np\nimport math\nS = np.array([list(map(int,list(input()))) for _ in range(H)])\ntotal = np.sum(S)\nif total==K:\n print(0)\nelse:\n print(math.ceil(total/K)//2)', 'H,W,K = map(int,input().split())\nimport numpy as np\nfrom collections import deque\nans = 10000\nS = np.array([list(map(int,list(input()))) for _ in range(H)])\ncum = [[0]*W for _ in range(H+1)]\nfor j in range(W):\n for i in range(1,H+1):\n cum[i][j] = cum[i-1][j]+S[i-1][j]\n \ncum = np.array(cum)', 'H,W,K = map(int,input().split())\nimport numpy as np\nfrom collections import deque\nans = 10000\nS = np.array([list(map(int,list(input()))) for _ in range(H)])\ncum = [[0]*W for _ in range(H+1)]\nfor j in range(W):\n for i in range(1,H+1):\n cum[i][j] = cum[i-1][j]+S[i-1][j]\n \ncum = np.array(cum)\nfor i in range(2**(H-1)):\n q = deque([0])\n for h in range(H):\n if (i>>h)&1:\n q.append(h+1)\n q.append(H)\n p = deque()\n for a in range(len(q)-1):\n x = cum[q[a+1]]-cum[q[a]]\n if (x>K).any():\n judge = True\n break\n else:\n p.append(x)\n\n if judge:\n continue\n \n t_a = len(q)-2\n l = [0]*len(p)\n judge = False\n for w in range(W):\n for x,a in enumerate(p):\n l[x]+=a[w]\n if l[x]>K:\n t_a+=1\n l = [0]*len(p)\n for z,b in enumerate(p):\n l[z] = b[w]\n break\n ans = min(ans,t_a)\n \nprint(ans)', 'H,W,K = map(int,input().split())\nimport numpy as np\nfrom collections import deque\nans = 10000\nS = np.array([list(map(int,list(input()))) for _ in range(H)])\ncum = [[0]*W for _ in range(H+1)]\nfor j in range(W):\n for i in range(1,H+1):\n cum[i][j] = cum[i-1][j]+S[i-1][j]\n \ncum = np.array(cum)\nfor i in range(2**(H-1)):\n q = deque([0])\n for h in range(H):\n if (i>>h)&1:\n q.append(h+1)\n q.append(H)\n q = list(q)\n p = deque()\n judge = False\n for a in range(len(q)-1):\n x = list(cum[q[a+1]]-cum[q[a]])\n if (x>K).any():\n judge = True\n break\n else:\n p.append(x)\n\n if judge:\n continue\n p = list(p)\n t_a = len(q)-2\n n = len(p)\n l = [0]*n\n for w in range(W):\n for x,a in enumerate(p):\n y = l[x]+a[w]\n if y>K:\n t_a+=1\n l = [0]*n\n for z,b in enumerate(p):\n l[z] = b[w]\n break\n else:\n l[x]=y\n ans = min(ans,t_a)\n \nprint(ans)', 'def main():\n H,W,K = map(int,input().split())\n import numpy as np\n from collections import deque\n ans = 10000\n S = np.array([list(map(int,list(input()))) for _ in range(H)])\n cum = [[0]*W for _ in range(H+1)]\n for j in range(W):\n for i in range(1,H+1):\n cum[i][j] = cum[i-1][j]+S[i-1][j]\n\n cum = np.array(cum)\n for i in range(2**(H-1)):\n j = 0\n q = deque([0])\n for h in range(H):\n if (i>>h)&1:\n q.append(h+1)\n q.append(H)\n t_a = len(q)-2\n if t_a>=ans:\n continue\n p = deque()\n judge = False\n for a in range(len(q)-1):\n x = cum[q[a+1]]-cum[q[a]]\n if (x>K).any():\n judge = True\n break\n else:\n p.append(list(x))\n\n if judge:\n continue\n n = len(p)\n l = [0]*n\n for w in range(W):\n y = [l[j]+p[j][w] for j in range(n)]\n if max(y)>K:\n t_a+=1\n l = [p[j][w] for j in range(n)]\n if t_a>=ans:\n judge = True\n break\n else:\n l = y\n if judge:\n continue\n ans = min(ans,t_a)\n\n print(ans)\n \nmain()'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s158383475', 's305588957', 's322662066', 's367720944', 's578480814', 's587732250', 's610168929', 's617562511', 's677282283', 's947970016', 's034194321'] | [12888.0, 12948.0, 14952.0, 12948.0, 12948.0, 2940.0, 12516.0, 12936.0, 12928.0, 12948.0, 12964.0] | [215.0, 499.0, 2109.0, 1216.0, 665.0, 17.0, 167.0, 164.0, 181.0, 161.0, 692.0] | [625, 752, 873, 926, 856, 1051, 205, 297, 870, 931, 1065] |
p02733 | u287132915 | 2,000 | 1,048,576 | We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`. We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar. How many times do we need to cut the bar so that every block after the cuts has K or less white squares? | ["import numpy as np\n\nh, w, k = map(int, input().split())\ns = []\nfor i in range(h):\n string = input()\n temp = []\n for j in range(w):\n temp.append(int(string[j]))\n s.append(temp)\n\ns_arr = np.array(s)\n\nans = 10**9\nfor i in range(2**(h-1)):\n bin_str = format(i, '0'+str(h-1)+'b')\n kouryo = np.array([[0 for _ in range(w)]])\n cnt = 0\n start = 0\n new = 0\n for j in range(h-1):\n if bin_str[j] == '1':\n cnt += 1\n new = s_arr[start:j+1].sum(axis=0, keepdims=True)\n if np.any(new>k):\n new = -1\n break\n kouryo = np.concatenate((kouryo, new), axis=0)\n start=j+1\n if new == -1: continue\n kouryo = np.concatenate((kouryo, s_arr[start:].sum(axis=0, keepdims=True)), axis=0)\n\n wa = kouryo[:, 0]\n for j in range(1, w):\n wa = wa + kouryo[:, j]\n if np.any(wa>k):\n cnt += 1\n wa = kouryo[:, j]\n ans = min(ans, cnt)\nprint(ans)", "import numpy as np\n\nh, w, k = map(int, input().split())\ns = []\nfor i in range(h):\n string = input()\n temp = []\n for j in range(w):\n temp.append(int(string[j]))\n s.append(temp)\n\ns_arr = np.array(s)\n\nans = 10**9\nfor i in range(2**(h-1)):\n bin_str = format(i, '0'+str(h-1)+'b')\n kouryo = np.array([[0 for _ in range(w)]])\n cnt = 0\n start = 0\n for j in range(h-1):\n if bin_str[j] == '1':\n cnt += 1\n new = s_arr[start:j+1].sum(axis=0, keepdims=True)\n if np.any(new>k):\n new = 0\n break\n kouryo = np.concatenate((kouryo, new), axis=0)\n start=j+1\n if new == 0: continue\n kouryo = np.concatenate((kouryo, s_arr[start:].sum(axis=0, keepdims=True)), axis=0)\n\n wa = kouryo[:, 0]\n for j in range(1, w):\n wa = wa + kouryo[:, j]\n if np.any(wa>k):\n cnt += 1\n wa = kouryo[:, j]\n ans = min(ans, cnt)\nprint(ans)", "import numpy as np\n\nh, w, k = map(int, input().split())\ns = []\nfor i in range(h):\n string = input()\n temp = []\n for j in range(w):\n temp.append(int(string[j]))\n s.append(temp)\n\nsum_s = [[0 for i in range(w)] for j in range(h)]\nif s[0][0] == 1: sum_s[0][0] = 1\nfor j in range(1, w):\n sum_s[0][j] = sum_s[0][j-1] + s[0][j]\nfor i in range(1, h):\n sum_s[i][0] = sum_s[i-1][0] + s[i][0]\nfor i in range(1, h):\n for j in range(1, w):\n sum_s[i][j] = sum_s[i-1][j] + sum_s[i][j-1] - sum_s[i-1][j-1] + s[i][j]\nsum_s = np.array(sum_s)\n\nans = 10**9\nfor i in range(2**(h-1)):\n bin_str = format(i, '0'+str(h-1)+'b')\n kouryo = []\n temp_s = sum_s[:]\n cnt = 0\n for j in range(h-1):\n if bin_str[j] == '1':\n cnt += 1\n kouryo.append(list(temp_s[j, :]))\n temp_s[j+1:, :] = temp_s[j+1:, :] - temp_s[j, :]\n kouryo.append(list(sum_s[h-1, :]))\n\n kouryo = np.array(kouryo)\n for j in range(1, w):\n if cnt >= 10**9: break\n for m in range(len(kouryo)):\n if cnt >= 10**9: break\n if kouryo[m, j] > k:\n kouryo[:, j:] = kouryo[:, j:] - kouryo[:, j-1]\n cnt += 1\n break\n for m in range(len(kouryo)):\n if kouryo[m, j-1] > k:\n cnt += 10**9\n break\n ans = min(ans, cnt)\nprint(ans)", "import numpy as np\n\nh, w, k = map(int, input().split())\ns = []\nfor i in range(h):\n string = input()\n temp = []\n for j in range(w):\n temp.append(int(string[j]))\n s.append(temp)\n\ns_arr = np.array(s)\n\nans = 10**9\nfor i in range(2**(h-1)):\n bin_str = format(i, '0'+str(h-1)+'b')\n kouryo = np.array([[0 for _ in range(w)]])\n cnt = 0\n start = 0\n for j in range(h-1):\n if bin_str[j] == '1':\n cnt += 1\n kouryo = np.concatenate((kouryo, s_arr[start:j+1].sum(axis=0, keepdims=True)), axis=0)\n start=j+1\n kouryo = np.concatenate((kouryo, s_arr[start:].sum(axis=0, keepdims=True)), axis=0)\n\n if cnt > ans: continue\n if np.any(kouryo>k): continue\n\n wa = np.array([0 for _ in range(len(kouryo))])\n for j in range(w):\n wa += kouryo[:, j]\n if np.max(wa)>k:\n cnt += 1\n if cnt > ans: break\n wa = kouryo[:, j]\n ans = min(ans, cnt)\nprint(ans)"] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s247206097', 's510807207', 's620058476', 's362897316'] | [12640.0, 12516.0, 12916.0, 13568.0] | [220.0, 154.0, 2109.0, 1599.0] | [983, 969, 1372, 961] |
p02733 | u368796742 | 2,000 | 1,048,576 | We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`. We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar. How many times do we need to cut the bar so that every block after the cuts has K or less white squares? | ['def main():\n import numpy as np\n h,w,k = map(int,input().split())\n l = [list(input()) for i in range(h)]\n\n def check(lis):\n \n num = np.zeros(len(lis))\n ans = 0\n for i in range(w):\n num2 = np.zeros(len(lis))\n for j in range(h):\n if l[j][i] == "1":\n num2[d[j]] += 1\n \n if np.max(num2) > k:\n return float("INF")\n else:\n num += num2\n if np.max(num) > k:\n ans += 1\n num = num2\n \n return ans\n\n ans = 10**9\n\n for i in range(2**(h-1)):\n count = 0\n lis1 = []\n d = []\n for j in range(h-1):\n d.append(count)\n if (i >> j) & 1:\n lis1.append(j)\n count += 1\n lis1.append(count+1)\n \n ans = min(ans,count+check(lis1))\n \n print(ans)\nif __name__ == "__main__":\n main()\n', 'def main():\n \n h,w,k = map(int,input().split())\n l = [list(input()) for i in range(h)]\n\n def check(lis):\n lis.append(h)\n num = [0]*(len(lis))\n ans = 0\n for i in range(w):\n ch = 0\n num2 = [0]*(len(lis))\n for j in range(h):\n \n if l[j][i] == "1":\n if j <= lis[ch]:\n num2[ch] += 1\n else:\n ch += 1\n num2[ch] += 1\n if max(num2) > k:\n return float("INF")\n else:\n for i in range(len(num)):\n num[i] += num2[i]\n if num[i] > k:\n ans += 1\n num = num2\n break \n \n \n return ans\n\n ans = 10**9\n\n for i in range(2**(h-1)):\n count = 0\n lis1 = []\n for j in range(h-1):\n if (i >> j) & 1:\n lis1.append(j)\n count += 1\n \n ans = min(ans,count+check(lis1))\n \n print(ans)\nif __name__ == "__main__":\n main()def main():\n \n h,w,k = map(int,input().split())\n l = [list(input()) for i in range(h)]\n\n def check(lis):\n lis.append(h)\n num = [0]*(len(lis))\n ans = 0\n for i in range(w):\n ch = 0\n num2 = [0]*(len(lis))\n for j in range(h):\n \n if l[j][i] == "1":\n if j <= lis[ch]:\n num2[ch] += 1\n else:\n ch += 1\n num2[ch] += 1\n if max(num2) > k:\n return float("INF")\n else:\n for i in range(len(num)):\n num[i] += num2[i]\n if num[i] > k:\n ans += 1\n num = num2\n break \n \n \n return ans\n\n ans = 10**9\n\n for i in range(2**(h-1)):\n count = 0\n lis1 = []\n for j in range(h-1):\n if (i >> j) & 1:\n lis1.append(j)\n count += 1\n \n ans = min(ans,count+check(lis1))\n \n print(ans)\nif __name__ == "__main__":\n main()', 'def main():\n \n h,w,k = map(int,input().split())\n l = [list(input()) for i in range(h)]\n\n def check(lis):\n \n num = [0]*(len(lis))\n ans = 0\n for i in range(w):\n num2 = [0]*(len(lis))\n for j in range(h):\n \n if l[j][i] == "1":\n num2[d[j]] += 1\n if max(num2) > k:\n return float("INF")\n else:\n for i in range(len(num)):\n num[i] += num2[i]\n if num[i] > k:\n ans += 1\n num = num2\n break \n \n \n return ans\n\n ans = 10**9\n\n for i in range(2**(h-1)):\n count = 0\n lis1 = []\n d = []\n for j in range(h):\n d.append(count)\n if (i >> j) & 1:\n lis1.append(j)\n count += 1\n lis1.append(count+1)\n ans = min(ans,count+check(lis1))\n \n print(ans)\nif __name__ == "__main__":\n main()'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s129215113', 's567753299', 's832035865'] | [14528.0, 3064.0, 3188.0] | [2108.0, 17.0, 1778.0] | [988, 2344, 1066] |
p02733 | u474423089 | 2,000 | 1,048,576 | We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`. We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar. How many times do we need to cut the bar so that every block after the cuts has K or less white squares? | ["import numpy as np\nfrom itertools import product\n\nH,W,K=map(int,input().split(' '))\narr = np.vstack([list(map(int,list(input()))) for j in range(H)])\nans = H+W-2\ncnt = 0\nd_cnt = 0\nfor p in product([0,1],repeat=H-1):\n cnt += 1\n sp=np.zeros((sum(p)+1,W),int)\n row=0\n sp[0]+=arr[0]\n for j in range(H-1):\n if p[j]:\n row+=1\n sp[row]+=arr[j+1]\n if np.max(sp)>K:\n continue\n sum_arr = np.zeros(len(sp),int)\n cut_cnt = sum(p)\n for c in range(W):\n sum_arr += sp[:,c]\n if max(sum_arr)>K:\n cut_cnt+=1\n sum_arr=sp[:,c]\n if cut_cnt > ans:\n break\n ans = min(cut_cnt,ans)\nprint(cnt,d_cnt)", "import numpy as np\nfrom itertools import product\n\nH,W,K=map(int,input().split(' '))\narr = np.vstack([[int(i) for i in input()] for j in range(H)])\nans = H+W-2\nfor p in product([0,1],repeat=H-1):\n if sum(p)>ans:\n continue\n sp=np.zeros((sum(p)+1,W),int)\n row=0\n sp[0]+=arr[0]\n for j in range(H-1):\n if p[j]:\n row+=1\n sp[row]+=arr[j+1]\n if np.max(sp)>K:\n continue\n sum_arr = np.zeros(len(sp),int)\n cut_cnt = sum(p)\n for c in range(W):\n sum_arr += sp[:,c]\n if max(sum_arr)>K:\n cut_cnt+=1\n sum_arr=sp[:,c]\n if cut_cnt > ans:\n break\n ans = min(cut_cnt,ans)\nprint(ans)"] | ['Wrong Answer', 'Accepted'] | ['s264125141', 's206716709'] | [14672.0, 12676.0] | [2108.0, 812.0] | [696, 692] |
p02733 | u486065927 | 2,000 | 1,048,576 | We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`. We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar. How many times do we need to cut the bar so that every block after the cuts has K or less white squares? | ['def add(in1, in2):\n return [a + b for a, b in zip(in1, in2)]\n\ndef split(ar, k, w):\n a = 0\n if max(ar) > k:\n return -1\n tm = ar[0]\n for i in range(1, w):\n tm = add(tm, ar[i])\n if max(tm) > k:\n a += 1\n tm = ar[i]\n return a \n\nh, w, k = map(int, input().split())\ns = [[int(i) for i in input()] for j in range(h)]\nans = h*w\n\nfor i in range(2**(h-1)):\n data = []\n temp = s[0]\n sp = bin(i+2**h)[4:]\n if ans < sp.count("1"):\n continue\n for j in range(1, h):\n if sp[j-1] == "0":\n temp = add(temp, s[j])\n else:\n data.append(temp)\n temp = s[j]\n data.append(temp)\n ans_ = split([list(x) for x in zip(*data)], k, w)\n if ans_ == -1:\n continue\n ans_ += sp.count("1")\n if ans > ans_:\n ans = ans_\nprint(ans)\n', 'def add(in1, in2):\n return [a + b for a, b in zip(in1, in2)]\n \ndef split(ar, k, w):\n a = 0\n if max(max(ar)) > k:\n return -1\n tm = ar[0]\n for i in range(1, w):\n tm = add(tm, ar[i])\n if max(tm) > k:\n a += 1\n tm = ar[i]\n return a \n \nh, w, k = map(int, input().split())\ns = [[int(i) for i in input()] for j in range(h)]\nans = h*w\n \nfor i in range(2**(h-1)):\n data = []\n temp = s[0]\n sp = bin(i+2**h)[4:]\n if ans < sp.count("1"):\n continue\n for j in range(1, h):\n if sp[j-1] == "0":\n temp = add(temp, s[j])\n else:\n data.append(temp)\n temp = s[j]\n data.append(temp)\n ans_ = split([list(x) for x in zip(*data)], k, w)\n if ans_ == -1:\n continue\n ans_ += sp.count("1")\n if ans > ans_:\n ans = ans_\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s717113043', 's735289908'] | [3188.0, 3364.0] | [21.0, 332.0] | [855, 863] |
p02733 | u550061714 | 2,000 | 1,048,576 | We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`. We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar. How many times do we need to cut the bar so that every block after the cuts has K or less white squares? | ['import numpy as np\nimport itertools\n\nH, W, K = map(int, input().split())\nS = np.array([[int(s) for s in input()] for _ in range(H)])\n\nans = 2000\nfor t in itertools.product([0, 1], repeat=H - 1):\n cut = t.count(1)\n lst = np.zeros((cut + 1, W), dtype=np.int)\n lst[0] += S[0]\n c = 0\n for h in range(H - 1):\n if t[h]:\n c += 1\n lst[c] += S[h + 1]\n L = len(lst)\n sum_lst = np.zeros(L)\n for w in range(W):\n lst_w = lst[:, w]\n if lst_w.max() > K:\n break\n\n lst_s = sum_lst + lst_w\n if lst_s.max() > K:\n cut += 1\n sum_lst = lst_w\n else:\n sum_lst = lst_s\n else:\n ans = min(ans, cut)\nprint(ans)\n', 'import itertools\n\nH, W, K = map(int, input().split())\nS = []\nfor _ in range(H):\n S.append([int(s) for s in input()])\n\nans = 2000\nfor t in itertools.product([0, 1], repeat=H - 1):\n cnt = t.count(1)\n lst = [[s for s in S[0]]]\n for h in range(H - 1):\n if t[h]:\n lst.append(S[h + 1])\n else:\n lst[-1] = [lst[-1][i] + S[h + 1][i] for i in range(W)]\n L = len(lst)\n sum_lst = [0] * L\n for w in range(W):\n if max(lst[i][w] for i in range(L)) > K:\n break\n tmp = [sum_lst[i] + lst[i][w] for i in range(L)]\n if max(tmp) > K:\n cnt += 1\n sum_lst = [lst[i][w] for i in range(L)]\n else:\n sum_lst = tmp\n else:\n ans = min(ans, cnt)\nprint(ans)\n'] | ['Time Limit Exceeded', 'Accepted'] | ['s386924895', 's307582026'] | [14668.0, 3188.0] | [2109.0, 1840.0] | [721, 764] |
p02733 | u614628638 | 2,000 | 1,048,576 | We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`. We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar. How many times do we need to cut the bar so that every block after the cuts has K or less white squares? | ["from collections import defaultdict\nfrom itertools import product\n \nH, W, K = map(int, input().split())\nS = [input() for _ in range(H)]\n \ni = 0\nwhile i < len(S):\n if '1' in S[i]:\n i += 1\n else:\n del S[i]\nH = len(S)\n \nC = [[int(s[i]) for s in S] for i in range(W)]\nprint(C)\ntotal = sum(sum(c) for c in C)\n \n\nanswer = H * W\nfor X in product([False, True], repeat=H-1):\n \n ans = sum(X)\n if ans > answer:\n continue\n M = [[0]]\n for i, x in enumerate(X):\n if x:\n M.append([])\n M[-1].append(i+1)\n D = [0] * len(M)\n for c in C:\n for k, m in enumerate(M):\n D[k] += sum(c[i] for i in m)\n \n if any(d > K for d in D):\n ans += 1\n if ans > answer:\n break\n D = [sum(c[i] for i in m) for m in M]\n if any(d > K for d in D):\n ans = answer + 1\n break\n answer = min(answer, ans)\n\nprint(answer)", "from collections import defaultdict\nfrom itertools import product\n \nH, W, K = map(int, input().split())\nS = [input() for _ in range(H)]\n \ni = 0\nwhile i < len(S):\n if '1' in S[i]:\n i += 1\n else:\n del S[i]\nH = len(S)\n \nC = [[int(s[i]) for s in S] for i in range(W)]\n \ntotal = sum(sum(c) for c in C)\n \nif total <= K:\n answer = 0\nelse:\n answer = H * W\n for X in product([False, True], repeat=H-1):\n \n ans = sum(X)\n if ans > answer:\n continue\n M = [[0]]\n for i, x in enumerate(X):\n if x:\n M.append([])\n M[-1].append(i+1)\n print('M{}'.format(M))\n D = [0] * len(M)\n for c in C:\n print('c{}'.format(c))\n for k, m in enumerate(M):\n print('m{}'.format(m))\n D[k] += sum(c[i] for i in m)\n \n print('D1{}'.format(D))\n if any(d > K for d in D):\n ans += 1\n if ans > answer:\n break\n D = [sum(c[i] for i in m) for m in M]\n print('D2{}'.format(D))\n if any(d > K for d in D):\n ans = answer + 1\n break\n answer = min(answer, ans)\n\nprint(answer)", "from collections import defaultdict\nfrom itertools import product\n \nH, W, K = map(int, input().split())\nS = [input() for _ in range(H)]\n \ni = 0\nwhile i < len(S):\n if '1' in S[i]:\n i += 1\n else:\n del S[i]\nH = len(S)\n \nC = [[int(s[i]) for s in S] for i in range(W)]\nprint(C)\ntotal = sum(sum(c) for c in C)\n \nif total <= K:\n answer = 0\nelse:\n answer = H * W\n for X in product([False, True], repeat=H-1):\n \n ans = sum(X)\n if ans > answer:\n continue\n M = [[0]]\n for i, x in enumerate(X):\n if x:\n M.append([])\n M[-1].append(i+1)\n D = [0] * len(M)\n for c in C:\n for k, m in enumerate(M):\n D[k] += sum(c[i] for i in m)\n \n if any(d > K for d in D):\n ans += 1\n if ans > answer:\n break\n D = [sum(c[i] for i in m) for m in M]\n if any(d > K for d in D):\n ans = answer + 1\n break\n answer = min(answer, ans)\n\nprint(answer)", "from collections import defaultdict\nfrom itertools import product\n \nH, W, K = map(int, input().split())\nS = [input() for _ in range(H)]\n \nC = [[int(s[i]) for s in S] for i in range(W)]\n \ntotal = sum(sum(c) for c in C)\n \nif total <= K:\n answer = 0\nelse:\n answer = H * W\n for X in product([False, True], repeat=H-1):\n \n ans = sum(X)\n if ans > answer:\n continue\n M = [[0]]\n for i, x in enumerate(X):\n if x:\n M.append([])\n M[-1].append(i+1)\n print('M{}'.format(M))\n D = [0] * len(M)\n for c in C:\n print('c{}'.format(c))\n for k, m in enumerate(M):\n print('m{}'.format(m))\n D[k] += sum(c[i] for i in m)\n \n print('D1{}'.format(D))\n if any(d > K for d in D):\n ans += 1\n if ans > answer:\n break\n D = [sum(c[i] for i in m) for m in M]\n print('D2{}'.format(D))\n if any(d > K for d in D):\n ans = answer + 1\n break\n answer = min(answer, ans)\n\nprint(answer)", "from collections import defaultdict\nfrom itertools import product\n \nH, W, K = map(int, input().split())\nS = [input() for _ in range(H)]\n \ni = 0\nwhile i < len(S):\n if '1' in S[i]:\n i += 1\n else:\n del S[i]\nH = len(S)\n \nC = [[int(s[i]) for s in S] for i in range(W)]\n \ntotal = sum(sum(c) for c in C)\n \nif total <= K:\n answer = 0\nelse:\n answer = H * W\n for X in product([False, True], repeat=H-1):\n ans = sum(X)\n M = [[0]]\n for i, x in enumerate(X):\n if x:\n M.append([])\n M[-1].append(i+1)\n print(M)\n D = [0] * len(M)\n print(M)\n for c in C:\n for k, m in enumerate(M):\n D[k] += sum(c[i] for i in m)\n if any(d > K for d in D):\n ans += 1\n if ans > answer:\n break\n D = [sum(c[i] for i in m) for m in M]\n if any(d > K for d in D):\n ans = answer + 1\n break\n answer = min(answer, ans)\n\nprint(answer)", 'from collections import defaultdict\nfrom itertools import product\n \nH,W,K = map(int,input().split())\nS = [input() for i in range(H)]\n \nC = [[int(S[i][k]) for i in range(H)] for k in range(W)]\nanswer = H*W \nfor X in product([False,True],repeat = H-1):\n M = [[0]]\n ans = sum(X)\n if ans > answer:\n continue\n for i,x in enumerate(X):\n if x:\n M.append([])\n M[-1].append(i+1)\n D = [0]*len(M)\n for c in C:\n for k,m in enumerate(M):\n D[k] += sum(c[i] for i in m)\n \n if any(d>K for d in D):\n ans += 1\n if ans >answer:\n break\n D = [sum(c[i] for i in m) for m in M]\n if any(d>K for d in D):\n ans = answer + 1\n \n break\n answer = min(answer,ans)\nprint(answer)'] | ['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s353102549', 's450917623', 's594482292', 's663866048', 's848478239', 's186717914'] | [3564.0, 13008.0, 3564.0, 13084.0, 3692.0, 3564.0] | [519.0, 2104.0, 516.0, 2104.0, 2103.0, 513.0] | [1387, 1612, 1470, 1525, 914, 1242] |
p02733 | u651663683 | 2,000 | 1,048,576 | We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`. We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar. How many times do we need to cut the bar so that every block after the cuts has K or less white squares? | ['h,w,kk=list(map(int,input().split()))\ns=[list(map(int,list(input()))) for i in range(h)]\nl=[]\nfor i in range(2**(h-1)):\n ll=[0]\n for j in range(h-1):\n if i & 2**j:\n ll.append(ll[-1]+1)\n else:\n ll.append(ll[-1])\n l.append(ll)\n\nmc=w+h\nfor i in l:\n c=[0 for i in range(h)]\n cc=0\n f=1\n #print(i,0)\n for j in range(w):\n #print(c)\n ff=0\n for k in range(h):\n c[i[k]]+=s[k][j]\n for k in range(h):\n if c[k]>kk:\n ff=1\n break\n if ff:\n if f:\n cc=w+h\n print(c)\n break\n cc+=1\n c=[0 for i in range(h)]\n for k in range(h):\n c[i[k]]+=s[k][j]\n f=0\n #print(cc)\n if mc>cc+len(set(i)-1):\n mc=cc\nprint(mc)\n ', 'h,w,kk=list(map(int,input().split()))\ns=[list(map(int,list(input()))) for i in range(h)]\nl=[]\nfor i in range(2**(h-1)):\n ll=[0]\n for j in range(h-1):\n if i & 2**j:\n ll.append(ll[-1]+1)\n else:\n ll.append(ll[-1])\n l.append(ll)\n\nmc=w+h\nfor i in l:\n c=[0 for i in range(h)]\n cc=0\n f=1\n #print(i,0)\n for j in range(w):\n #print(c)\n ff=0\n for k in range(h):\n c[i[k]]+=s[k][j]\n for k in range(h):\n if c[k]>kk:\n ff=1\n break\n if ff:\n cc+=1\n c=[0 for i in range(h)]\n for k in range(h):\n c[i[k]]+=s[k][j]\n for k in range(h):\n if c[k]>kk:\n f=1\n if f:\n cc=w+h\n #print(c)\n break\n f=0\n #print(cc)\n if mc>cc+len(set(i))-1:\n mc=cc+len(set(i))-1\nprint(mc)'] | ['Runtime Error', 'Accepted'] | ['s495250510', 's195979166'] | [9296.0, 9268.0] | [28.0, 1486.0] | [711, 776] |
p02733 | u671455949 | 2,000 | 1,048,576 | We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`. We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar. How many times do we need to cut the bar so that every block after the cuts has K or less white squares? | ["import itertools\n\nh, w, k = map(int, input().split())\ns = [['0' for i in range(w)] for j in range(h)]\n\nfor i in range(h):\n s[i] = input()\n\ncnt = [[0 for i in range(w)] for j in range(h)]\nfor i in range(h):\n cnt[i][0] = int(s[i][0]) + (0 if i == 0 else cnt[i - 1][0])\n\nfor i in range(w):\n cnt[0][i] = int(s[0][i]) + (0 if i == 0 else cnt[0][i - 1])\n\nfor i in range(1, h):\n for j in range(1, w):\n cnt[i][j] = cnt[i - 1][j] + cnt[i][j - 1] - cnt[i - 1][j - 1] + int(s[i][j])\n\nnum = [i for i in range(h - 1)]\nans = 99999\nfor i in range(0, h):\n for v in itertools.combinations(num, i):\n n = list(v)\n n.append(h - 1)\n \n _ans = i\n _left = -1\n for j in range(w):\n for _k in range(len(n)):\n if cnt[n[_k]][j] - (0 if _left < 0 else cnt[n[_k]][_left]) - (0 if _k == 0 else cnt[n[_k - 1]][j]) + (0 if _left < 0 or _k == 0 else cnt[n[_k - 1]][_left]) > k:\n _left = j\n _ans += 1\n break\n ans = min(ans, _ans)\n\nprint(ans)", "import itertools\n\nh, w, k = map(int, input().split())\ns = [['0' for i in range(w)] for j in range(h)]\n\nfor i in range(h):\n s[i] = input()\n\ncnt = [[0 for i in range(w)] for j in range(h)]\nfor i in range(h):\n cnt[i][0] = int(s[i][0]) + (0 if i == 0 else cnt[i - 1][0])\n\nfor i in range(w):\n cnt[0][i] = int(s[0][i]) + (0 if i == 0 else cnt[0][i - 1])\n\nfor i in range(1, h):\n for j in range(1, w):\n cnt[i][j] = cnt[i - 1][j] + cnt[i][j - 1] - cnt[i - 1][j - 1] + int(s[i][j])\n\nnum = [i for i in range(h - 1)]\nans = 99999\nfor i in range(0, h):\n for v in itertools.combinations(num, i):\n n = list(v)\n n.append(h - 1)\n \n _ans = i\n _left = -1\n for j in range(w):\n for _k in range(len(n)):\n if cnt[n[_k]][j] - (0 if _left < 0 else cnt[n[_k]][_left]) - (0 if _k == 0 else cnt[n[_k - 1]][j]) + (0 if _left < 0 or _k == 0 else cnt[n[_k - 1]][_left]) > k:\n if j - _left == 1:\n _ans = 99999\n break\n _left = j - 1\n j -= 1\n _ans += 1\n break\n ans = min(ans, _ans)\n\nprint(ans)"] | ['Wrong Answer', 'Accepted'] | ['s938867599', 's462825475'] | [3440.0, 3440.0] | [1812.0, 1688.0] | [973, 1066] |
p02733 | u678167152 | 2,000 | 1,048,576 | We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`. We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar. How many times do we need to cut the bar so that every block after the cuts has K or less white squares? | ["import itertools\nH, W, K = map(int, input().split())\n\nS = [0]*H\nfor i in range(H):\n S[i] = input()\nSdivs = []\nmcnt = 1100\nfor b in itertools.product([0, 1], repeat=H-1):\n start = 0\n end = 1\n Sdivs=[]\n for a in b:\n if a==1:\n Sdivs.append(S[start:end])\n start = end\n end += 1\n Sdivs.append(S[start:end])\n cnt = sum(b)\n ones_cum = [0]*len(Sdivs)\n ones = [0]*len(Sdivs)\n mark1,mark2 = False,False\n ws = [0]\n for w in range(1,W):\n if mark2 == True:\n #print(mark)\n break\n for i,Sdiv in enumerate(Sdivs):\n #print(w)\n for s in Sdiv:\n ones_cum[i] += s[w-1]=='1'\n ones[i] += s[w-1]=='1'\n if ones_cum[i] > K:\n mark1 = True\n if w-1 == ws[-1]:\n mark2 = True\n ws.append(w-1)\n \n if mark1 == True:\n mark1 = False\n ones_cum = ones\n ones = [0]*len(Sdivs)\n if mark2 == True:\n continue\n cnt += len(ws)-1\n mcnt = min(mcnt,cnt)\nprint(mcnt)\n \n \n \n \n\n", 'from itertools import groupby, accumulate, product, permutations, combinations\ndef solve():\n H, W, K = map(int, input().split())\n S = [input() for _ in range(H)]\n cum = [[0]*(W+1) for _ in range(H+1)]\n for i in range(1,H+1):\n for j in range(1,W+1):\n cum[i][j]=cum[i-1][j]+cum[i][j-1]-cum[i-1][j-1]+int(S[i-1][j-1])\n ans = 2000\n for p in product([0,1],repeat=H-1):\n line = [0]\n p = list(p)\n cnt = sum(p)\n for i in range(1,H):\n if p[i-1]==1:\n line.append(i)\n line.append(H)\n w_s = 0\n w_e = 1\n b = False\n while w_e <= W:\n for i in range(len(line)-1):\n h_s = line[i]\n h_e = line[i+1]\n white = cum[h_e][w_e]+cum[h_s][w_s]-cum[h_e][w_s]-cum[h_s][w_e]\n if white > K:\n if w_e == w_s+1:\n b = True\n break\n else:\n w_s = w_e-1\n cnt += 1\n break\n if b==True:\n break\n w_e += 1\n else:\n ans = min(ans,cnt)\n return ans\nprint(solve())\n'] | ['Wrong Answer', 'Accepted'] | ['s135090065', 's884581741'] | [3064.0, 9408.0] | [2104.0, 815.0] | [988, 1223] |
p02733 | u686230543 | 2,000 | 1,048,576 | We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`. We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar. How many times do we need to cut the bar so that every block after the cuts has K or less white squares? | ['import numpy as np\n\nh, w, k = map(int, input().split())\ns = np.array(\n [[int(s_ij) for s_ij in input()] for _ in range(h)],\n dtype=np.int)\n\nminimum = (h - 1) * (w - 1)\nfor div_h in range(1 << (h - 1)):\n h_index = np.zeros(h, dtype=np.int)\n cur_index = 0\n for i in range(1, h):\n if div_h & 1:\n cur_index += 1\n h_index[i] = cur_index\n div_h >>= 1\n white_choco = np.zeros(cur_index + 1, dtype=np.int)\n divide = 0\n j = 0\n while j < w:\n for i in range(h):\n if s[i, j]:\n if white_choco[h_index[i]] < k:\n white_choco[h_index[i]] += 1\n else:\n break\n else:\n j += 1\n continue\n white_choco[:] = 0\n divide += 1\n minimum = min(minimum, divide + cur_index)\nprint(minimum)', 'import numpy as np\n\nh, w, k = map(int, input().split())\ns = np.array(\n [[s for s in map(int, input().split())] for _ in range(h)],\n dtype=np.int)\n\nminimum = (h - 1) * (w - 1)\nfor div_h in range(1 << (h - 1)):\n h_index = np.zeros(h, dtype=np.int)\n cur_index = 0\n for i in range(1, h):\n if div_h & 1:\n cur_index += 1\n h_index[i] = cur_index\n div_h >>= 1\n white_choco = np.zeros(cur_index + 1, dtype=np.int)\n divide = 0\n j = 0\n while j < w:\n for i in range(h):\n if s[i, j]:\n if white_choco[h_index[i]] < k:\n white_choco[h_index[i]] += 1\n else:\n break\n else:\n j += 1\n continue\n white_choco[:] = 0\n divide += 1\n minimum = min(minimum, divide + cur_index)\nprint(minimum)', "h, w, k = map(int, input().split())\ns = [input() for _ in range(h)]\n\nminimum = (h - 1) * (w - 1)\nfor div_h in range(1 << (h - 1)):\n h_index = [0] * h\n cur_index = 0\n mask = 1 << (h - 2)\n for i in range(1, h):\n if div_h & mask:\n cur_index += 1\n h_index[i] = cur_index\n mask >>= 1\n white_choco = [0] * (cur_index + 1)\n divide = 0\n for j in range(w):\n for i in range(h):\n if s[i][j] == '1':\n if white_choco[h_index[i]] < k:\n white_choco[h_index[i]] += 1\n else:\n break\n else:\n continue\n white_choco = [0] * (cur_index + 1)\n divide += 1\n minimum = min(minimum, divide + cur_index)\nprint(minimum)", "h, w, k = map(int, input().split())\ns = [input() for _ in range(h)]\n\nminimum = (h - 1) * (w - 1)\nfor div_h in range(1 << (h - 1)):\n h_index = [0] * h\n cur_index = 0\n mask = 1 << (h - 2)\n for i in range(1, h):\n if div_h & mask:\n cur_index += 1\n h_index[i] = cur_index\n mask >>= 1\n white_choco = [0] * (cur_index + 1)\n divide = 0\n j = 0\n while j < w:\n for i in range(h):\n if s[i][j] == '1':\n if white_choco[h_index[i]] < k:\n white_choco[h_index[i]] += 1\n else:\n break\n else:\n j += 1\n continue\n white_choco = [0] * (cur_index + 1)\n divide += 1\n print(h_index, divide)\n minimum = min(minimum, divide + cur_index)\nprint(minimum)", 'h, w, k = map(int, input().split())\ns = [[int(s_ij) for s_ij in input()] for _ in range(h)]\n\nminimum = (h - 1) * (w - 1)\nfor div_h in range(1 << (h - 1)):\n h_index = [0] * h\n cur_index = 0\n mask = 1 << (h - 2)\n for i in range(1, h):\n if div_h & mask:\n cur_index += 1\n h_index[i] = cur_index\n mask >>= 1\n white_choco = [0] * (cur_index + 1)\n divide = 0\n j = 0\n flag = False\n while j < w:\n for i in range(h):\n white_choco[h_index[i]] += s[i][j]\n if max(white_choco) > k:\n if flag:\n break\n flag = True\n white_choco = [0] * (cur_index + 1)\n divide += 1\n else:\n j += 1\n flag = False\n else:\n minimum = min(minimum, divide + cur_index)\nprint(minimum)'] | ['Time Limit Exceeded', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s133221314', 's188450752', 's275261403', 's439110948', 's985947830'] | [14552.0, 12488.0, 3064.0, 3188.0, 3192.0] | [2108.0, 149.0, 2061.0, 2104.0, 1632.0] | [740, 747, 666, 706, 721] |
p02733 | u704284486 | 2,000 | 1,048,576 | We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`. We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar. How many times do we need to cut the bar so that every block after the cuts has K or less white squares? | ['from collections import deque\ndef main():\n H,W,K = map(int,input().split())\n S = [[int(s) for s in input()]for _ in range(H)]\n ans = 2**60\n for i in range(2**(H-1)):\n aa = 0\n for j in range(H-1):\n if (i>>j)&1 == 1:\n aa+=1\n c = aa\n b = [0 for _ in range(c+1)]\n OK = True\n for j in range(W):\n k = 0\n for h in range(H):\n if S[h][j]:b[k] += 1\n if (i>>j)&1==1:k+=1\n \n ok = True\n for p in b:\n if p > K:ok = False\n if not ok:\n aa += 1\n b = [0]*(c+1)\n k = 0\n for h in range(H):\n if S[h][j]:b[k] += 1\n if (i>>j)&1==1:k+=1\n ok = True\n for p in b:\n if p > K:ok = False\n if not ok:OK = False;break \n if OK:ans = min(ans,aa)\n print(ans)\n\nif __name__ == "__main__":\n main()', 'def main():\n H,W,K = map(int,input().split())\n S = [input()for _ in range(H)]\n ans = 10**9\n for i in range(2**(H-1)):\n aa = 0\n for j in range(H-1):\n if (i>>j)&1 == 1:\n aa+=1\n c = aa\n b = [0]*(c+1)\n OK = True\n for j in range(W):\n k = 0\n for h in range(H):\n if S[h][j] == "1":b[k] += 1\n if (i>>h)&1==1:k+=1\n \n ok = True\n for p in b:\n if p > K:ok = False\n if not ok:\n aa += 1\n b = [0]*(c+1)\n \n k = 0\n for h in range(H):\n if S[h][j]=="1":b[k] += 1\n if (i>>h)&1==1:k+=1\n ok = True\n for p in b:\n if p > K:ok = False\n if not ok:OK = False;break \n if OK:ans = min(ans,aa)\n print(ans)\n\nif __name__ == "__main__":\n main()'] | ['Runtime Error', 'Accepted'] | ['s821889724', 's691423601'] | [3436.0, 3064.0] | [976.0, 1567.0] | [1020, 1007] |
p02733 | u711693740 | 2,000 | 1,048,576 | We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`. We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar. How many times do we need to cut the bar so that every block after the cuts has K or less white squares? | ["def main():\n from itertools import product\n \n H, W, K = map(int, input().split())\n S = [input() for _ in range(H)]\n S_T = [[int(s[w]) for s in S] for w in range(W)]\n sumS = sum(map(sum, S_T))\n ans = (H - 1) * (W - 1)\n \n if sumS <= K:\n print(0)\n else:\n for i in product([True, False], repeat=H-1):\n cnt = sum(i)\n if cnt >= ans:\n continue\n M = [[0]]\n for j, k in enumerate(i):\n if k:\n M.append([])\n M[-1].append(j+1)\n A = [0] * len(M)\n for s_t in S_T:\n for l, m in enumerate(M):\n A[l] += sum(s_t[i] for i in m)\n if any(a > K for a in A):\n cnt += 1\n if cnt >= ans:\n break\n A = [sum(s_t[i] for i in m) for m in M]\n if any(a > K for a in A):\n cnt = ans + 1\n break\n ans = min(cnt, ans)\n print(ans)\n\nif __name__ == '__main__'\n main()", "def main():\n from itertools import product\n\n H, W, K = map(int, input().split())\n S = [input() for _ in range(H)]\n S_T = [[int(s[w]) for s in S] for w in range(W)]\n sumS = sum(map(sum, S_T))\n ans = (H - 1) * (W - 1)\n\n if sumS <= K:\n print(0)\n else:\n for i in product([True, False], repeat=H-1):\n cnt = sum(i)\n if cnt >= ans:\n continue\n M = [[0]]\n for j, k in enumerate(i):\n if k:\n M.append([])\n M[-1].append(j+1)\n A = [0] * len(M)\n for s_t in S_T:\n for l, m in enumerate(M):\n A[l] += sum(s_t[i] for i in m)\n if any(a > K for a in A):\n cnt += 1\n if cnt >= ans:\n break\n A = [sum(s_t[i] for i in m) for m in M]\n if any(a > K for a in A):\n cnt = ans + 1\n break\n ans = min(cnt, ans)\n print(ans)\n\nif __name__ == '__main__':\n main()"] | ['Runtime Error', 'Accepted'] | ['s338264343', 's383524023'] | [3064.0, 3188.0] | [17.0, 360.0] | [1115, 1108] |
p02733 | u726285999 | 2,000 | 1,048,576 | We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`. We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar. How many times do we need to cut the bar so that every block after the cuts has K or less white squares? | ['import numpy as np\nimport itertools\n\nH, W, K = map(int, input().split())\nchoco = []\nfor i in range(H):\n choco.append([int(x) for x in list(input())])\n\narr = np.array(choco)\n\n\ncount = (H-1) + (W-1)\n\nfor k in range(H):\n \n \n if count <= k:\n break\n\n \n for comb in itertools.combinations(range(1,H),k):\n\n \n t = (None,) + comb + (None,)\n s = [slice(t[j],t[j+1],) for j in range(len(t)-1)]\n \n # print(t)\n \n sum_p = [0] * (k+1)\n \n cut = k\n \n for col in zip(*choco):\n \n \n sum_a = [sum(col[b]) for b in s]\n # print(sum_a)\n \n if any(map(K.__lt__, sum_a)):\n \n break\n \n sum_b = [x+y for x,y in zip(sum_p, sum_a)]\n\n if any(map(K.__lt__, sum_b)):\n cut += 1\n sum_p = [0] * (k+1)\n else:\n sum_p = sum_b\n \n \n \n else:\n count = min(count,cut)\n\nprint(count)', 'import numpy as np\nimport itertools\n\nH, W, K = map(int, input().split())\nchoco = []\nfor i in range(H):\n choco.append([int(x) for x in list(input())])\n\narr = np.array(choco)\n\n\ncount = (H-1) + (W-1)\n\nfor cho in choco:\n print(cho)\n\nfor k in range(H):\n print(k)\n \n \n if count <= k:\n break\n\n \n for comb in itertools.combinations(range(1,H),k):\n\n \n t = (None,) + comb + (None,)\n s = [slice(t[j],t[j+1],) for j in range(len(t)-1)]\n \n # print(t)\n \n sum_p = [0] * (k+1)\n \n cut = k\n \n for col in zip(*choco):\n\n \n sum_a = [sum(col[b]) for b in s]\n \n \n if any(map(K.__lt__, sum_a)):\n \n break\n \n \n \n sum_b = [x + y for x,y in zip(sum_p, sum_a)]\n print(k, sum_b)\n\n if any(map(K.__lt__, sum_b)):\n cut += 1\n sum_p = sum_a\n else:\n sum_p = sum_b\n \n \n \n else:\n count = min(count,cut)\n\nprint(count)', 'import numpy as np\nimport itertools\n\nH, W, K = map(int, input().split())\nchoco = []\nfor i in range(H):\n choco.append([int(x) for x in list(input())])\n\narr = np.array(choco)\n\n\nprint(H, W, K)\ncount = (H-1) + (W-1)\n\nfor k in range(H):\n \n \n if count <= k:\n break\n\n \n for comb in itertools.combinations(range(1,H),k):\n\n \n t = (None,) + comb + (None,)\n s = [slice(t[j],t[j+1],) for j in range(len(t)-1)]\n \n # print(t)\n \n sum_p = [0] * (k+1)\n \n cut = k\n \n for col in zip(*choco):\n \n \n sum_a = [sum(col[b]) for b in s]\n # print(sum_a)\n \n if any(map(K.__lt__, sum_a)):\n \n break\n \n sum_b = [x+y for x,y in zip(sum_p, sum_a)]\n\n if any(map(K.__lt__, sum_b)):\n cut += 1\n sum_p = [0] * (k+1)\n else:\n sum_p = sum_b\n \n \n \n else:\n count = min(count,cut)\n\nprint(count)', 'import numpy as np\nimport itertools\n\nH, W, K = map(int, input().split())\nchoco = []\nfor i in range(H):\n choco.append([int(x) for x in list(input())])\n\narr = np.array(choco)\n\n\ncount = (H-1) + (W-1)\n\n\nfor k in range(H):\n \n \n if count <= k:\n break\n\n \n for comb in itertools.combinations(range(1,H),k):\n\n \n t = (None,) + comb + (None,)\n s = [slice(t[j],t[j+1],) for j in range(len(t)-1)]\n \n sum_p = [0] * (k+1)\n \n cut = k\n \n for col in zip(*choco):\n\n \n sum_a = [sum(col[b]) for b in s]\n \n \n if any(map(K.__lt__, sum_a)):\n \n break\n \n \n \n sum_b = [x + y for x,y in zip(sum_p, sum_a)]\n\n if any(map(K.__lt__, sum_b)):\n cut += 1\n sum_p = sum_a\n else:\n sum_p = sum_b\n \n \n \n else:\n count = min(count,cut)\n\nprint(count)'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s051317299', 's472824255', 's812048118', 's857377418'] | [14596.0, 16080.0, 12548.0, 14580.0] | [705.0, 1068.0, 709.0, 707.0] | [1298, 1504, 1313, 1402] |
p02733 | u727057618 | 2,000 | 1,048,576 | We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`. We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar. How many times do we need to cut the bar so that every block after the cuts has K or less white squares? | ['import itertools\nimport numpy as np\n\nres = 999999999999999999\n\nH, W, K = [int(i) for i in input().split()]\narr = []\nfor h in range(H):\n arr.append([int(v) for v in input()])\n\narr = np.vstack(arr)\nprint(arr)\n \nfor p in itertools.product([0, 1], repeat = H-1):\n sp = np.zeros((sum(p)+1, W), int)\n row = 0\n sp[0] += arr[0]\n for j in range(H-1):\n if p[j]:\n row += 1\n sp[row] += arr[j+1]\n if np.max(sp) > K:\n continue\n \n sum_arr = np.zeros(len(sp), int)\n cut_cnt = sum(p)\n for c in range(W):\n sum_arr += sp[:, c]\n if max(sum_arr) > K:\n sum_arr = sp[:, c]\n cut_cnt += 1\n if cut_cnt < res:\n res = cut_cnt\nprint(res)', 'import itertools\nimport numpy as np\n\nres = 999999999999999999\n\nH, W, K = [int(i) for i in input().split()]\narr = []\nfor h in range(H):\n arr.append([int(v) for v in input()])\n\narr = np.vstack(arr)\n\nfor p in itertools.product([0, 1], repeat = H-1):\n if sum(p) > res:\n continue\n sp = np.zeros((sum(p)+1, W), int)\n row = 0\n sp[0] += arr[0]\n for j in range(H-1):\n if p[j]:\n row += 1\n sp[row] += arr[j+1]\n if np.max(sp) > K:\n continue\n \n sum_arr = np.zeros(len(sp), int)\n cut_cnt = sum(p)\n for c in range(W):\n sum_arr += sp[:, c]\n if max(sum_arr) > K:\n sum_arr = sp[:, c]\n cut_cnt += 1\n if cut_cnt > res:\n break\n if cut_cnt < res:\n res = cut_cnt\nprint(res)'] | ['Wrong Answer', 'Accepted'] | ['s248622333', 's769952487'] | [14700.0, 12696.0] | [2108.0, 838.0] | [653, 710] |
p02733 | u735891571 | 2,000 | 1,048,576 | We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`. We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar. How many times do we need to cut the bar so that every block after the cuts has K or less white squares? | ['import itertools\nH, W, K = map(int,input().split())\nS = [list(map(int,list(input()))) for _ in range(H)]\ndef check(k):\n if k <= K:\n return(True)\n else:\n return(False)\n \nnoans = 0\ndef make_lst(i):\n global noans, lst, havelst\n temp = S[0][i]\n for h in range(H-1):\n if y[h]:\n lst.append(temp)\n temp = S[h+1][i]\n else:\n temp += S[h+1][i]\n lst.append(temp)\n if check(max(lst)):\n havelst = 1\n else:\n noans = 1\n \ndef nocut(i):\n global cutnum, lst, havelst\n prelst = []\n temp = S[0][i]\n j = 0\n for h in range(H-1):\n if y[h]:\n lst[j] += temp\n prelst.append(temp)\n j += 1\n temp = S[h+1][i]\n else:\n temp += S[h+1][i]\n prelst.append(temp)\n lst[-1] += temp\n if check(max(lst)):\n return(True)\n else:\n cutnum += 1\n lst = prelst \n \nans = float("inf")\ncutlst = [] \nfor y in itertools.product((0, 1), repeat=H-1):\n havelst = 0\n lst = []\n cutnum = sum(y)\n for x in range(W):\n if noans:\n \tnoans = 0\n break\n if havelst:\n nocut(x)\n else:\n make_lst(x)\n ans = min(cutnum, ans)\nprint(ans)\n \n', 'import itertools\nH, W, K = map(int,input().split())\nS = [list(map(int,list(input()))) for _ in range(H)]\ndef check(k):\n if k <= K:\n return(True)\n else:\n return(False)\n \nnoans = 0\ndef make_lst(i):\n global noans, lst, havelst\n temp = S[0][i]\n for h in range(H-1):\n if y[h]:\n lst.append(temp)\n temp = S[h+1][i]\n else:\n temp += S[h+1][i]\n lst.append(temp)\n if check(max(lst)):\n havelst = 1\n else:\n noans = 1\n# print(y,i,lst, "makelst")\n \ndef nocut(i):\n global cutnum, lst, havelst, noans\n prelst = []\n temp = S[0][i]\n if i == W-1:\n if not check(temp):\n noans = 1\n j = 0\n for h in range(H-1): \n if y[h]:\n lst[j] += temp\n prelst.append(temp)\n j += 1\n temp = S[h+1][i]\n else:\n temp += S[h+1][i]\n if i == W-1:\n if not check(temp):\n noans = 1\n prelst.append(temp)\n lst[-1] += temp\n if check(max(lst)):\n\n return(True)\n else:\n cutnum += 1\n lst = prelst \n\n \n \nans = float("inf") \nfor y in itertools.product((0, 1), repeat=H-1):\n havelst = 0\n lst = []\n cutnum = sum(y)\n for x in range(W):\n if noans:\n break\n if havelst:\n nocut(x)\n else:\n make_lst(x)\n# print(y,cutnum)\n if noans:\n noans = 0\n continue\n else:\n ans = min(cutnum, ans)\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s144872077', 's199958531'] | [3064.0, 3188.0] | [18.0, 1937.0] | [1322, 1660] |
p02733 | u798316285 | 2,000 | 1,048,576 | We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`. We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar. How many times do we need to cut the bar so that every block after the cuts has K or less white squares? | ["def main():\n import sys\n input=sys.stdin.readline\n h,w,k=map(int,input().split())\n S=[]\n for _ in range(h):\n s=list(map(int,list(input().rstrip())))\n S.append(s)\n ans=10**5\n for i in range(2**(h-1)):\n l=[0]\n for j in range(h-1):\n if i&1<<j:\n l.append(l[-1]+1)\n else:\n l.append(l[-1]) \n ans_=l[-1]\n ll=[0]*h\n for j in range(w):\n for p in range(h):\n ll[l[p]]+=S[p][j]\n if ll[l[p]]>k:\n ans_+=1\n ll=[0]*h\n ans=min(ans,ans_)\n print(ans)\nif __name__ == '__main__':\n main()", "def main():\n import sys\n input=sys.stdin.readline\n h,w,k=map(int,input().split())\n S=[]\n for _ in range(h):\n s=list(map(int,list(input().rstrip())))\n S.append(s)\n ans=10**5\n for i in range(2**(h-1)):\n l=[0]\n for j in range(h-1):\n if i&1<<j:\n l.append(l[-1]+1)\n else:\n l.append(l[-1]) \n ans_=l[-1]\n ll=[0]*h\n j=0\n flag=0\n while j<w:\n for p in range(h):\n ll[l[p]]+=S[p][j]\n if max(ll)>k and flag==0:\n flag=1\n ans_+=1\n ll=[0]*h\n elif max(ll)>k and flag==1:\n ans_=10**5\n break\n else:\n j+=1\n flag=0\n ans=min(ans,ans_)\n print(ans)\nif __name__ == '__main__':\n main()"] | ['Wrong Answer', 'Accepted'] | ['s996094081', 's390726995'] | [3188.0, 3188.0] | [1560.0, 1182.0] | [680, 872] |
p02733 | u844789719 | 2,000 | 1,048,576 | We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`. We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar. How many times do we need to cut the bar so that every block after the cuts has K or less white squares? | ["import numpy as np\nimport itertools\nH, W, K = [int(_) for _ in input().split()]\nS = np.zeros((H + 1, W + 1), dtype=int)\nS[1:, 1:] = [[int(_) for _ in input()] for _ in range(H)]\ncum = S.cumsum(axis=0).cumsum(axis=1)\n#sum(a,b -> x,y) (1-indexed)\n#cum[x][y]+cum[a-1][b-1]-cum[a-1][y]-cum[x][b-1]\nans = 10**10\nfor bs in itertools.product([True, False], repeat=H - 1):\n bs = [True] + list(bs) + [True]\n idxs = []\n for i, b in enumerate(bs):\n if b:\n idxs += [i]\n cum2 = np.array([cum[i2] - cum[i1] for i1, i2 in zip(idxs, idxs[1:])])\n i = 0\n cnt = sum(bs) - 3\n while i < W:\n i = min(np.searchsorted(c, K + c[i], side='right') for c in cum2)\n cnt += 1\n ans = min(ans, cnt)\nprint(ans)\n", "from numba import njit\nimport numpy as np\nimport itertools\nH, W, K = [int(_) for _ in input().split()]\nS = np.zeros((H + 1, W + 1), dtype=int)\nS[1:, 1:] = [[int(_) for _ in input()] for _ in range(H)]\n\n\ndef solve(H, W, K, S):\n cum = S.cumsum(axis=0).cumsum(axis=1)\n #sum(a,b -> x,y) (1-indexed)\n #cum[x][y]+cum[a-1][b-1]-cum[a-1][y]-cum[x][b-1]\n ans = 10**10\n for bs in itertools.product([True, False], repeat=H - 1):\n bs = [True] + list(bs) + [True]\n idxs = []\n for i, b in enumerate(bs):\n if b:\n idxs += [i]\n cum2 = np.array([cum[i2] - cum[i1] for i1, i2 in zip(idxs, idxs[1:])])\n i = 0\n cnt = sum(bs) - 3\n f = True\n while i < W:\n i2 = min(np.searchsorted(c, K + c[i], side='right') for c in cum2)\n if i2 == i:\n f = False\n break\n i = i2\n cnt += 1\n if f:\n ans = min(ans, cnt)\n print(ans)\n\n\nsolve(H, W, K, S)\n", "import numpy as np\nimport itertools\nH, W, K = [int(_) for _ in input().split()]\nS = np.zeros((H + 1, W + 1), dtype=int)\nS[1:, 1:] = [[int(_) for _ in input()] for _ in range(H)]\ncum = S.cumsum(axis=0).cumsum(axis=1)\n#sum(a,b -> x,y) (1-indexed)\n#cum[x][y]+cum[a-1][b-1]-cum[a-1][y]-cum[x][b-1]\nans = 10**10\nfor bs in itertools.product([True, False], repeat=H - 1):\n bs = [True] + list(bs) + [True]\n idxs = []\n for i, b in enumerate(bs):\n if b:\n idxs += [i]\n cum2 = np.array([cum[i2] - cum[i1] for i1, i2 in zip(idxs, idxs[1:])])\n i = 0\n cnt = sum(bs) - 3\n while i < W:\n di = min(\n np.searchsorted(c[i + 1:] - c[i], K, side='right') for c in cum2)\n if di == 0:\n cnt = 10**10\n break\n i += di\n cnt += 1\n ans = min(ans, cnt)\nprint(ans)\n"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s741170264', 's936150760', 's947308170'] | [27368.0, 91948.0, 27504.0] | [2206.0, 2207.0, 214.0] | [734, 1001, 835] |
p02733 | u871980676 | 2,000 | 1,048,576 | We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`. We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar. How many times do we need to cut the bar so that every block after the cuts has K or less white squares? | ['from itertools import product\nimport numpy as np\nimport time\nimport random\n\nH, W, K = map(int, input().split())\ns = [np.array(list(input()), dtype=np.int32) for _ in range(H)]\n\nstart = time.time()\n\n\n\ns2 = [np.cumsum(row, dtype=np.int32) for row in s]\n\nrate = H*W//5\nmi = 10 ** 9\nseed = [0, 1]\ntgt = product(seed, repeat=H-1)\nselected = []\n# for ls in tgt:\nwhile time.time()-start < 1.9:\n t = random.choices(seed, k=H - 1)\n if t in selected:\n continue\n selected.append(t)\n ls = t\n \n num = sum(ls)+1\n tmp = num - 1\n \n s3 = np.zeros((num, W))\n s3[0] = s2[0]\n cnt = 0\n for i in range(H - 1):\n if ls[i] == 0:\n s3[cnt] += s2[i + 1]\n else:\n cnt += 1\n s3[cnt] = s2[i + 1]\n s3 = s3.T\n \n hosei = np.zeros(num)\n for w in range(W):\n if np.max(s3[:][w] - hosei) > K:\n tmp += 1\n if w != 0:\n hosei = s3[:][w - 1]\n else:\n tmp = 10 ** 9\n if mi > tmp:\n mi = tmp\nz = 0\nfor row in s:\n z += np.sum(row)\nif z <= K:\n mi = 0\nprint(mi)\n\n\n', 'import numpy as np\nimport time\nimport random\n\nH, W, K = map(int, input().split())\ns = [np.array(list(input()), dtype=np.int32) for _ in range(H)]\n\nstart = time.time()\n\n\n\ns2 = [np.cumsum(row, dtype=np.int32) for row in s]\n\nmi = 10 ** 9\nseed = [0] * 1000 + [1] * 1000\nselected = []\n\n\nls = [0]*(H-1)\n\nnum = 1\ntmp = 0\n\ns3 = np.zeros((num, W))\ns3[0] = s2[0]\ncnt = 0\nfor i in range(H - 1):\n if ls[i] == 0:\n s3[cnt] += s2[i + 1]\n else:\n cnt += 1\n s3[cnt] = s2[i + 1]\ns3 = s3.T\n\nhosei = np.zeros(num)\nfor w in range(W):\n if np.max(s3[:][w] - hosei) > K:\n tmp += 1\n if w != 0:\n hosei = s3[:][w - 1]\n else:\n tmp = 10 ** 9\nif mi > tmp:\n mi = tmp\n\n\n\nls = [1]*(H-1)\n\nnum = H\ntmp = num - 1\n\ns3 = np.zeros((num, W))\ns3[0] = s2[0]\ncnt = 0\nfor i in range(H - 1):\n if ls[i] == 0:\n s3[cnt] += s2[i + 1]\n else:\n cnt += 1\n s3[cnt] = s2[i + 1]\ns3 = s3.T\n\nhosei = np.zeros(num)\nfor w in range(W):\n if np.max(s3[:][w] - hosei) > K:\n tmp += 1\n if w != 0:\n hosei = s3[:][w - 1]\n else:\n tmp = 10 ** 9\nif mi > tmp:\n mi = tmp\n \nwhile time.time() - start < 1.7:\n t = random.sample(seed, k=H - 1)\n if t in selected:\n continue\n selected.append(t)\n ls = t\n \n num = sum(ls) + 1\n tmp = num - 1\n \n s3 = np.zeros((num, W))\n s3[0] = s2[0]\n cnt = 0\n for i in range(H - 1):\n if ls[i] == 0:\n s3[cnt] += s2[i + 1]\n else:\n cnt += 1\n s3[cnt] = s2[i + 1]\n s3 = s3.T\n \n hosei = np.zeros(num)\n for w in range(W):\n if np.max(s3[:][w] - hosei) > K:\n tmp += 1\n if w != 0:\n hosei = s3[:][w - 1]\n else:\n tmp = 10 ** 9\n if mi > tmp:\n mi = tmp\nz = 0\nfor row in s:\n z += np.sum(row)\nif z <= K:\n mi = 0\nprint(mi)\n\n\n'] | ['Runtime Error', 'Accepted'] | ['s752829014', 's018814381'] | [15220.0, 20024.0] | [160.0, 1984.0] | [1205, 2064] |
p02733 | u899308536 | 2,000 | 1,048,576 | We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`. We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar. How many times do we need to cut the bar so that every block after the cuts has K or less white squares? | ['import numpy as np\nH,W,K = list(map(int,input().split()))\n\n\nS = [0]*H\nfor i in range(H):\n S[i] = list(map(int,list(input())))\n# print(S)\nS = np.array(S)\n# print(S)\n# print(np.sum(S[0:3,0:3]))\n\n# n=0\nif np.sum(S) <= K:\n print(0)\n exit()\n\n# n=1\nfor i in range(1,H):\n # print("i:",i)\n # print(S[:i,:],S[i:,:])\n if np.sum(S[:i,:])<=K and np.sum(S[i:,:])<=K:\n print(1)\n exit()\n\nfor i in range(1,W):\n # print("i:",i)\n # print(S[:,:i],S[:,i:])\n if np.sum(S[:,:i])<=K and np.sum(S[:,i:])<=K:\n print(1)\n exit()\n', 'import itertools\n\nH, W, K = map(int, input().split())\nS = []\nfor _ in range(H):\n S.append([int(s) for s in input()])\n# print(S)\n\nans = 2000\nfor t in itertools.product([0, 1], repeat=H - 1):\n \n cnt = t.count(1)\n lst = [[s for s in S[0]]]\n for h in range(H - 1):\n if t[h]: \n lst.append(S[h + 1])\n else: \n lst[-1] = [lst[-1][i] + S[h + 1][i] for i in range(W)] \n L = len(lst)\n # print("lst:",lst)\n # print(cnt,L)\n sum_lst = [0] * L\n for w in range(W):\n \n if max(lst[i][w] for i in range(L)) > K:\n # print("break")\n break\n tmp = [sum_lst[i] + lst[i][w] for i in range(L)]\n # print("w=",w,tmp)\n if max(tmp) > K:\n cnt += 1\n \n sum_lst = [lst[i][w] for i in range(L)]\n # print(sum_lst)\n else:\n sum_lst = tmp\n else: \n ans = min(ans, cnt)\nprint(ans)\n"""\nfor t in itertools.product([0, 1], repeat=H - 1):\n print(t)\n"""'] | ['Wrong Answer', 'Accepted'] | ['s978656990', 's321165156'] | [12632.0, 3188.0] | [188.0, 1877.0] | [596, 1192] |
p02733 | u968649733 | 2,000 | 1,048,576 | We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`. We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar. How many times do we need to cut the bar so that every block after the cuts has K or less white squares? | ['import sys\nread = sys.stdin.read\nreadline = sys.stdin.readline\nreadlines = sys.stdin.readlines\n\ndef main():\n H,W,K = map(int, readline().split())\n S = [list(map(int, readline().strip())) for j in range(H)]\n \n print(H,W,S)\n \n white = 0\n for line in S:\n white += sum(line)\n \n if white <= K:\n print(0)\n exit()\n \n Pdb().set_trace()\n \n ans = 10**5\n \n \n \n for pattern in range(2**(H-1)):\n \n impossible = False\n x = 0\n ly = bin(pattern).count("1")\n y = [S[0]]\n line = 0\n for i in range(1,H):\n if (pattern >> i-1) & 1:\n line += 1\n y.append(S[i])\n else:\n y[line] = [y[line][j] + S[i][j] for j in range(W)]\n \n \n count = [0]*(ly + 1) \n for j in range(W):\n for i in range(line+1):\n if y[i][j] > K :\n impossible = True\n break\n \n count[i] += y[i][j]\n \n \n \n if count[i] > K:\n x += 1\n for i in range(line+1):\n count[i] = y[i][j]\n break\n \n if x + ly > ans or impossible:\n impossible = True\n break\n if impossible:\n x = 10**6\n \n ans = min(ans, x + ly)\n \n print(ans)', 'import sys\nread = sys.stdin.read\nreadline = sys.stdin.readline\nreadlines = sys.stdin.readlines\n\ndef main():\n H,W,K = map(int, readline().split())\n S = [list(map(int, readline().strip())) for j in range(H)]\n \n white = 0\n for line in S:\n white += sum(line)\n \n if white <= K:\n print(0)\n exit()\n \n \n ans = 10**5\n \n \n \n for pattern in range(2**(H-1)):\n \n impossible = False\n x = 0\n ly = bin(pattern).count("1")\n y = [S[0]]\n line = 0\n for i in range(1,H):\n if (pattern >> i-1) & 1:\n line += 1\n y.append(S[i])\n else:\n y[line] = [y[line][j] + S[i][j] for j in range(W)]\n \n \n count = [0]*(ly + 1) \n for j in range(W):\n for i in range(line+1):\n if y[i][j] > K :\n impossible = True\n break\n \n count[i] += y[i][j]\n \n \n \n if count[i] > K:\n x += 1\n for i in range(line+1):\n count[i] = y[i][j]\n break\n \n if x + ly > ans or impossible:\n impossible = True\n break\n if impossible:\n x = 10**6\n \n ans = min(ans, x + ly)\n \n print(ans)\n \n \nmain()'] | ['Wrong Answer', 'Accepted'] | ['s826771527', 's240369461'] | [3064.0, 3192.0] | [17.0, 394.0] | [2067, 2034] |
p02733 | u987164499 | 2,000 | 1,048,576 | We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares. The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`. We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar. How many times do we need to cut the bar so that every block after the cuts has K or less white squares? | ['from itertools import accumulate\n\nh,w,k = map(int,input().split())\ns = [list(map(int,"".join(input()))) for _ in range(h)]\n\nmin_split = 10**10\n\nfor i in range(2**(h-1)):\n li = []\n for j in range(h-1):\n if (i >> j)&1:\n li.append(j)\n li.append(h-1)\n lin = [0]*w\n total = []\n for l in range(h):\n for m in range(w):\n lin[m] += s[l][m]\n if l in li:\n total.append(lin)\n lin = [0]*w\n now = 0\n t = len(total)\n count = t-1\n for n in range(t):\n total[n] = list(accumulate(total[n]))\n for o in range(w):\n for p in range(t):\n if total[p][o]-total[p][now] > k:\n now = o\n count += 1\n break\n min_split = min(min_split,count)\n\nprint(min_split)', 'from itertools import accumulate\n\nh,w,k = map(int,input().split())\ns = [list(map(int,"".join(input()))) for _ in range(h)]\n\nmin_split = 10**10\n\nfor i in range(2**(h-1)):\n li = []\n\n for j in range(h-1):\n if (i >> j)&1:\n li.append(j)\n li.append(h-1)\n lin = [0]*w\n total = []\n\n over = False\n\n for l in range(h):\n for m in range(w):\n lin[m] += s[l][m]\n if lin[m] > k:\n over = True\n if l in li:\n total.append(lin)\n lin = [0]*w\n\n if over:\n continue\n\n now = 0\n t = len(total)\n count = t-1\n\n for n in range(t):\n total[n] = [0]+list(accumulate(total[n]))\n for o in range(1,w+1):\n for p in range(t):\n if total[p][o]-total[p][now] > k:\n now = o-1\n count += 1\n break\n\n min_split = min(min_split,count)\n\nprint(min_split)'] | ['Wrong Answer', 'Accepted'] | ['s752467090', 's593099431'] | [9544.0, 9436.0] | [1373.0, 1644.0] | [798, 917] |
p02734 | u044220565 | 2,000 | 1,048,576 | Given are a sequence of N integers A_1, A_2, \ldots, A_N and a positive integer S. For a pair of integers (L, R) such that 1\leq L \leq R \leq N, let us define f(L, R) as follows: * f(L, R) is the number of sequences of integers (x_1, x_2, \ldots , x_k) such that L \leq x_1 < x_2 < \cdots < x_k \leq R and A_{x_1}+A_{x_2}+\cdots +A_{x_k} = S. Find the sum of f(L, R) over all pairs of integers (L, R) such that 1\leq L \leq R\leq N. Since this sum can be enormous, print it modulo 998244353. | ['# coding: utf-8\nimport itertools\nA = [0]\nN, S = list(map(int, input().split()))\nA = A + list(map(int, input().split())) \nprint(N,S,A)\nval = 0\nfor L in range(1, N+1):\n for R in range(L, N+1):\n A_ = A[L:R+1]\n lists = []\n for n in range(len(A_)):\n for comb in itertools.combinations(A_, n+1):\n lists.append(list(comb))\n for lis in lists:\n _sum = sum(lis)\n if _sum == S:\n val += 1\nprint(val % 998244353)', '# coding: utf-8\nimport itertools\nA = [0]\nN, S = list(map(int, input().split()))\nA = A + list(map(int, input().split())) \nprint(N,S,A)\nval = 0\nfor L in range(1, N+1):\n for R in range(L, N+1):\n A_ = A[L:R+1]\n lists = []\n for n in range(len(A_)):\n for comb in itertools.combinations(A_, n+1):\n lists.append(list(comb))\n for lis in lists:\n _sum = sum(lis)\n if _sum == S:\n val += 1\n if val == 998244353:\n val = 0\nprint(val)', '# coding: utf-8\nimport numpy as np\nmod = 998244353\nN, S = list(map(int, input().split()))\nA = [0] + list(map(int, input().split()))\n\ndp = np.array([[0 for _ in range(S+1)] for i in range(N+1)])\n\nfor k in range(0, N):\n dp[k+1,:] += (2 * dp[k,:] - dp[k-1,:]) % mod\n if S > A[k+1]:\n dp[k+1, A[k+1]+1:] += (dp[k, 1:S-A[k+1]+1] - dp[k-1, 1:S-A[k+1]+1]) % mod\n if A[k+1] <= S:\n dp[k+1,A[k+1]] += k+1\n\nprint(dp[N,S] % mod)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s471741052', 's713798478', 's086256682'] | [223312.0, 223312.0, 161044.0] | [2118.0, 2122.0, 1628.0] | [443, 474, 424] |
p02734 | u102461423 | 2,000 | 1,048,576 | Given are a sequence of N integers A_1, A_2, \ldots, A_N and a positive integer S. For a pair of integers (L, R) such that 1\leq L \leq R \leq N, let us define f(L, R) as follows: * f(L, R) is the number of sequences of integers (x_1, x_2, \ldots , x_k) such that L \leq x_1 < x_2 < \cdots < x_k \leq R and A_{x_1}+A_{x_2}+\cdots +A_{x_k} = S. Find the sum of f(L, R) over all pairs of integers (L, R) such that 1\leq L \leq R\leq N. Since this sum can be enormous, print it modulo 998244353. | ['from numpy import *\nM=998244353\nN,S,*A=map(int,open(0).read().split())\na=0\nf = np.zeros(S+1, np.int64)\nfor b in As:\n f[0]+=1\n f[b:] += f[:-b].copy()\n f%=M\n a+=f[S]\nprint(a%M)', 'from numpy import *\nM=998244353\nN,S,*A=map(int,open(0).read().split())\na=0\nf=zeros(S+1,int)\nfor b in A:\n f[0]+=1\n f[b:] += f[:-b].copy()\n f%=M\n a+=f[S]\nprint(a%M)'] | ['Runtime Error', 'Accepted'] | ['s646479404', 's339757507'] | [12508.0, 20500.0] | [152.0, 343.0] | [178, 166] |
p02734 | u111473084 | 2,000 | 1,048,576 | Given are a sequence of N integers A_1, A_2, \ldots, A_N and a positive integer S. For a pair of integers (L, R) such that 1\leq L \leq R \leq N, let us define f(L, R) as follows: * f(L, R) is the number of sequences of integers (x_1, x_2, \ldots , x_k) such that L \leq x_1 < x_2 < \cdots < x_k \leq R and A_{x_1}+A_{x_2}+\cdots +A_{x_k} = S. Find the sum of f(L, R) over all pairs of integers (L, R) such that 1\leq L \leq R\leq N. Since this sum can be enormous, print it modulo 998244353. | ['def main():\n import sys\n sys.setrecursionlimit(10**9)\n input = sys.stdin.readline\n import numpy as np\n\n mod = 998244353\n\n N, S = map(int, input().split())\n A = list(map(int, input().split()))\n\n \n polynomial = np.zeros(S+1, int)\n ans = 0\n for i in A:\n polynomial[0] += 1\n polynomial[i:] += polynomial[:-i].copy()\n polynomial %= mod\n ans += polynomial[S]\n\nmain()', 'def main():\n import sys\n sys.setrecursionlimit(10**9)\n input = sys.stdin.readline\n import numpy as np\n\n mod = 998244353\n\n N, S = map(int, input().split())\n A = list(map(int, input().split()))\n\n \n polynomial = np.zeros(S+1, int)\n ans = 0\n for i in A:\n polynomial[0] += 1\n polynomial[i:] += polynomial[:-i].copy()\n polynomial %= mod\n ans += polynomial[S]\n\n print(ans % mod)\n\nmain()'] | ['Wrong Answer', 'Accepted'] | ['s473343473', 's121414346'] | [12492.0, 12500.0] | [296.0, 300.0] | [432, 454] |
p02734 | u266014018 | 2,000 | 1,048,576 | Given are a sequence of N integers A_1, A_2, \ldots, A_N and a positive integer S. For a pair of integers (L, R) such that 1\leq L \leq R \leq N, let us define f(L, R) as follows: * f(L, R) is the number of sequences of integers (x_1, x_2, \ldots , x_k) such that L \leq x_1 < x_2 < \cdots < x_k \leq R and A_{x_1}+A_{x_2}+\cdots +A_{x_k} = S. Find the sum of f(L, R) over all pairs of integers (L, R) such that 1\leq L \leq R\leq N. Since this sum can be enormous, print it modulo 998244353. | ["def main():\n import sys\n def input(): return sys.stdin.readline().rstrip()\n n, s = map(int, input().split())\n a = list(map(int, input().split()))\n import numpy as np\n dp = np.zeros(s+1, dtype=int)\n dp[0] = 1\n mod = 998244353\n ans = 0\n for i in range(n):\n dp[0] += 1\n dp[a[i]:] += dp[:-a[i]]\n dp%= mod\n ans += dp[-1]\n ans %= mod\n print(ans)\n\n\n\nif __name__ == '__main__':\n main()", "def main():\n import sys\n def input(): return sys.stdin.readline().rstrip()\n n, s = map(int, input().split())\n a = list(map(int, input().split()))\n import numpy as np\n dp = np.zeros(s+1, dtype=int)\n mod = 998244353\n ans = 0\n for i in range(n):\n dp[0] += 1\n dp[a[i]:] += dp[:-a[i]]\n dp%= mod\n ans += dp[-1]\n ans %= mod\n print(ans)\n\n\n\nif __name__ == '__main__':\n main()"] | ['Wrong Answer', 'Accepted'] | ['s526150924', 's217827076'] | [27376.0, 26664.0] | [284.0, 221.0] | [448, 434] |
p02734 | u340781749 | 2,000 | 1,048,576 | Given are a sequence of N integers A_1, A_2, \ldots, A_N and a positive integer S. For a pair of integers (L, R) such that 1\leq L \leq R \leq N, let us define f(L, R) as follows: * f(L, R) is the number of sequences of integers (x_1, x_2, \ldots , x_k) such that L \leq x_1 < x_2 < \cdots < x_k \leq R and A_{x_1}+A_{x_2}+\cdots +A_{x_k} = S. Find the sum of f(L, R) over all pairs of integers (L, R) such that 1\leq L \leq R\leq N. Since this sum can be enormous, print it modulo 998244353. | ['import numpy as np\n\nn, s = map(int, input().split())\naaa = list(map(int, input().split()))\n\nfwd_acc = np.zeros((n + 1, s + 1), dtype=np.int64)\nfwd_acc[0][0] = 1\n\nans = 0\nMOD = 998244353\nfor i, a in enumerate(aaa, start=1):\n fwd_acc[i] = fwd_acc[i - 1]\n fwd_acc[i][0] = i\n if a <= s:\n fwd_acc[i][a:] += fwd_acc[i][:-a]\n ans = (ans + fwd_acc[i - 1][s - a] * (n - i + 1)) % MOD\nprint(ans)\n', 'import numpy as np\n\nn, s = map(int, input().split())\naaa = list(map(int, input().split()))\n\nfwd_acc = np.zeros((n + 1, s + 1), dtype=np.int64)\nfwd_acc[0][0] = 1\n\nans = 0\nMOD = 998244353\nfor i, a in enumerate(aaa, start=1):\n fwd_acc[i] = fwd_acc[i - 1]\n fwd_acc[i][0] = i\n if a <= s:\n fwd_acc[i][a:] = fwd_acc[i][a:] + fwd_acc[i][:-a]\n fwd_acc[i] %= MOD\n ans = (ans + fwd_acc[i][s]) % MOD\n # print(fwd_acc)\n # print(ans)\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s057376987', 's973225796'] | [82768.0, 82764.0] | [216.0, 331.0] | [405, 459] |
p02734 | u561231954 | 2,000 | 1,048,576 | Given are a sequence of N integers A_1, A_2, \ldots, A_N and a positive integer S. For a pair of integers (L, R) such that 1\leq L \leq R \leq N, let us define f(L, R) as follows: * f(L, R) is the number of sequences of integers (x_1, x_2, \ldots , x_k) such that L \leq x_1 < x_2 < \cdots < x_k \leq R and A_{x_1}+A_{x_2}+\cdots +A_{x_k} = S. Find the sum of f(L, R) over all pairs of integers (L, R) such that 1\leq L \leq R\leq N. Since this sum can be enormous, print it modulo 998244353. | ["import sys \nMOD = 10**9 +7\nINF = 10**5\n\ndef main():\n n,s = map(int,input().split())\n a = list(map(int,input().split()))\n\n dp = [[0] * (s + 1) for _ in range(n + 1)]\n for i in range(n):\n num = a[i]\n for j in range(1,s + 1):\n dp[i + 1][j] = dp[i][j] + dp[i][j - a[i]]\n \n print(dp[-1][-1])\nif __name__=='__main__':\n main()", "import sys\nsys.setrecursionlimit(10000000)\nMOD = 998244353\nINF = 10 ** 18\n\nimport numpy as np\ndef main():\n N,S = map(int,input().split())\n A = list(map(int,input().split()))\n \n before = np.zeros(S + 1,np.int64)\n before[0] = 1\n ans = 0\n for a in A:\n now = np.zeros(S + 1,np.int64)\n now += before\n now[a:] += before[:-a]\n ans += now[S]\n ans %= MOD\n now[0] += 1\n now = np.mod(now,MOD)\n before = now\n print(ans)\nif __name__ == '__main__':\n main()\n\n"] | ['Runtime Error', 'Accepted'] | ['s014008013', 's828065140'] | [75892.0, 14412.0] | [2109.0, 323.0] | [365, 527] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.