TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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?

Submission attempts (in order):
import itertools

H, W, K = map(int, input().split())
S = []
for _ in range(H):
    S.append([int(s) for s in input()])
    

ans = 2000
for t in itertools.product([0, 1], repeat=H - 1):
    cnt = t.count(1)
    #print(cnt)
    lst = [[s for s in S[0]]]
    for h in range(H - 1):
        
        #print(lst
        
        if t[h]:
            lst.append(S[h + 1])
            
        else:
            lst[-1] = [lst[-1][i] + S[h + 1][i] for i in range(W)]
            
        #print(lst)
    L = len(lst)
    print(L)
    sum_lst = [0] * L
    
    for w in range(W):
        if max(lst[i][w] for i in range(L)) > K:
            break
            
        tmp = [sum_lst[i] + lst[i][w] for i in range(L)]
        if max(tmp) > K:
            cnt += 1 
            sum_lst = [lst[i][w] for i in range(L)]
        else:
            sum_lst = tmp 
    else:
        ans = min(ans, cnt)
        
print(ans)


import itertools

H, W, K = map(int, input().split())
S = []
for _ in range(H):
    S.append([int(s) for s in input()])
    

ans = 2000
for t in itertools.product([0, 1], repeat=H - 1):
    cnt = t.count(1)
    #print(cnt)
    lst = [[s for s in S[0]]]
    for h in range(H - 1):
        
        #print(lst
        
        if t[h]:
            lst.append(S[h + 1])
            
        else:
            lst[-1] = [lst[-1][i] + S[h + 1][i] for i in range(W)]
            
        #print(lst)
    L = len(lst)
    #print(L)
    sum_lst = [0] * L
    
    for w in range(W):
        if max(lst[i][w] for i in range(L)) > K:
            break
            
        tmp = [sum_lst[i] + lst[i][w] for i in range(L)]
        if max(tmp) > K:
            cnt += 1 
            sum_lst = [lst[i][w] for i in range(L)]
        else:
            sum_lst = tmp 
    else:
        ans = min(ans, cnt)
        
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):

import numpy as np

H, W, K = map(int, input().split())
S = np.zeros((H, W), dtype=np.int64)

ans = H+W

for i in range(H):
    S[i] = list(str(input()))

for m in range(2**(H-1)):
    wp = np.zeros((H, W), dtype=np.int64)
    wq = np.zeros((H, ), dtype=np.int64)
    wp[0] = S[0]
    cut = 0
    for n in range(H-1):
        if m>>n&1:
            cut += 1
        wp[cut] += S[n+1]

    if cut >= ans or np.count_nonzero(wp > K):
        continue

    for j in range(W): 
        wq += wp[-1,j]
        if np.count_nonzero(wq > K):
            cut += 1
            wq = wp[-1,j]
    ans = min(ans, cut)

print(ans)




import numpy as np

H, W, K = map(int, input().split())
S = np.zeros((H, W), dtype=np.int64)

ans = H+W

for i in range(H):
    S[i] = list(str(input()))

for m in range(1<<(H-1)):
    cut = bin(m).count('1')
    if cut >= ans:
        continue

    wp = np.zeros((cut+1, W), dtype=np.int64)
    wp[0] = S[0]
    c = 0
    for n in range(H-1):
        if m>>n&1:
            c += 1
        wp[c] += S[n+1]

    if np.count_nonzero(wp > K):
        continue

    wq = np.zeros((cut+1, ), dtype=np.int64)
    for j in range(W):
        wq += wp[:,j]
        if np.count_nonzero(wq > K):
            cut += 1
            wq = wp[:,j]

    ans = min(ans, cut)

print(ans)




Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
import numpy as np
from itertools import product

H,W,K=map(int,input().split(' '))
arr = np.vstack([list(map(int,list(input()))) for j in range(H)])
ans = H+W-2
cnt = 0
d_cnt = 0
for p in product([0,1],repeat=H-1):
    cnt += 1
    sp=np.zeros((sum(p)+1,W),int)
    row=0
    sp[0]+=arr[0]
    for j in range(H-1):
        if p[j]:
            row+=1
        sp[row]+=arr[j+1]
    if np.max(sp)>K:
        continue
    sum_arr = np.zeros(len(sp),int)
    cut_cnt = sum(p)
    for c in range(W):
        sum_arr += sp[:,c]
        if max(sum_arr)>K:
            cut_cnt+=1
            sum_arr=sp[:,c]
            if cut_cnt > ans:
                break
    ans = min(cut_cnt,ans)
print(cnt,d_cnt)

import numpy as np
from itertools import product

H,W,K=map(int,input().split(' '))
arr = np.vstack([[int(i) for i in input()] for j in range(H)])
ans = H+W-2
for p in product([0,1],repeat=H-1):
    if sum(p)>ans:
        continue
    sp=np.zeros((sum(p)+1,W),int)
    row=0
    sp[0]+=arr[0]
    for j in range(H-1):
        if p[j]:
            row+=1
        sp[row]+=arr[j+1]
    if np.max(sp)>K:
        continue
    sum_arr = np.zeros(len(sp),int)
    cut_cnt = sum(p)
    for c in range(W):
        sum_arr += sp[:,c]
        if max(sum_arr)>K:
            cut_cnt+=1
            sum_arr=sp[:,c]
            if cut_cnt > ans:
                break
    ans = min(cut_cnt,ans)
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
def add(in1, in2):
    return [a + b for a, b in zip(in1, in2)]

def split(ar, k, w):
    a = 0
    if max(ar) > k:
      return -1
    tm = ar[0]
    for i in range(1, w):
        tm = add(tm, ar[i])
        if max(tm) > k:
            a += 1
            tm = ar[i]
    return a        

h, w, k = map(int, input().split())
s = [[int(i) for i in input()] for j in range(h)]
ans = h*w

for i in range(2**(h-1)):
    data = []
    temp = s[0]
    sp = bin(i+2**h)[4:]
    if ans < sp.count("1"):
        continue
    for j in range(1, h):
        if sp[j-1] == "0":
            temp = add(temp, s[j])
        else:
            data.append(temp)
            temp = s[j]
    data.append(temp)
    ans_ = split([list(x) for x in zip(*data)], k, w)
    if ans_ == -1:
        continue
    ans_ += sp.count("1")
    if ans > ans_:
        ans = ans_
print(ans)


def add(in1, in2):
    return [a + b for a, b in zip(in1, in2)]
 
def split(ar, k, w):
    a = 0
    if max(max(ar)) > k:
      return -1
    tm = ar[0]
    for i in range(1, w):
        tm = add(tm, ar[i])
        if max(tm) > k:
            a += 1
            tm = ar[i]
    return a        
 
h, w, k = map(int, input().split())
s = [[int(i) for i in input()] for j in range(h)]
ans = h*w
 
for i in range(2**(h-1)):
    data = []
    temp = s[0]
    sp = bin(i+2**h)[4:]
    if ans < sp.count("1"):
        continue
    for j in range(1, h):
        if sp[j-1] == "0":
            temp = add(temp, s[j])
        else:
            data.append(temp)
            temp = s[j]
    data.append(temp)
    ans_ = split([list(x) for x in zip(*data)], k, w)
    if ans_ == -1:
        continue
    ans_ += sp.count("1")
    if ans > ans_:
        ans = ans_
print(ans)


Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
import numpy as np
import itertools

H, W, K = map(int, input().split())
S = np.array([[int(s) for s in input()] for _ in range(H)])

ans = 2000
for t in itertools.product([0, 1], repeat=H - 1):
    cut = t.count(1)
    lst = np.zeros((cut + 1, W), dtype=np.int)
    lst[0] += S[0]
    c = 0
    for h in range(H - 1):
        if t[h]:
            c += 1
        lst[c] += S[h + 1]
    L = len(lst)
    sum_lst = np.zeros(L)
    for w in range(W):
        lst_w = lst[:, w]
        if lst_w.max() > K:
            break

        lst_s = sum_lst + lst_w
        if lst_s.max() > K:
            cut += 1
            sum_lst = lst_w
        else:
            sum_lst = lst_s
    else:
        ans = min(ans, cut)
print(ans)


import itertools

H, W, K = map(int, input().split())
S = []
for _ in range(H):
    S.append([int(s) for s in input()])

ans = 2000
for t in itertools.product([0, 1], repeat=H - 1):
    cnt = t.count(1)
    lst = [[s for s in S[0]]]
    for h in range(H - 1):
        if t[h]:
            lst.append(S[h + 1])
        else:
            lst[-1] = [lst[-1][i] + S[h + 1][i] for i in range(W)]
    L = len(lst)
    sum_lst = [0] * L
    for w in range(W):
        if max(lst[i][w] for i in range(L)) > K:
            break
        tmp = [sum_lst[i] + lst[i][w] for i in range(L)]
        if max(tmp) > K:
            cnt += 1
            sum_lst = [lst[i][w] for i in range(L)]
        else:
            sum_lst = tmp
    else:
        ans = min(ans, cnt)
print(ans)


Verdicts: Time Limit Exceeded

Accepted
Problem: 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?

Submission attempts (in order):
h,w,kk=list(map(int,input().split()))
s=[list(map(int,list(input()))) for i in range(h)]
l=[]
for i in range(2**(h-1)):
  ll=[0]
  for j in range(h-1):
    if i & 2**j:
      ll.append(ll[-1]+1)
    else:
      ll.append(ll[-1])
  l.append(ll)

mc=w+h
for i in l:
  c=[0 for i in range(h)]
  cc=0
  f=1
  #print(i,0)
  for j in range(w):
    #print(c)
    ff=0
    for k in range(h):
      c[i[k]]+=s[k][j]
    for k in range(h):
      if c[k]>kk:
        ff=1
        break
    if ff:
      if f:
        cc=w+h
        print(c)
        break
      cc+=1
      c=[0 for i in range(h)]
      for k in range(h):
        c[i[k]]+=s[k][j]
    f=0
  #print(cc)
  if mc>cc+len(set(i)-1):
    mc=cc
print(mc)
        

h,w,kk=list(map(int,input().split()))
s=[list(map(int,list(input()))) for i in range(h)]
l=[]
for i in range(2**(h-1)):
  ll=[0]
  for j in range(h-1):
    if i & 2**j:
      ll.append(ll[-1]+1)
    else:
      ll.append(ll[-1])
  l.append(ll)

mc=w+h
for i in l:
  c=[0 for i in range(h)]
  cc=0
  f=1
  #print(i,0)
  for j in range(w):
    #print(c)
    ff=0
    for k in range(h):
      c[i[k]]+=s[k][j]
    for k in range(h):
      if c[k]>kk:
        ff=1
        break
    if ff:
      cc+=1
      c=[0 for i in range(h)]
      for k in range(h):
        c[i[k]]+=s[k][j]
      for k in range(h):
        if c[k]>kk:
          f=1
      if f:
        cc=w+h
        #print(c)
        break
    f=0
  #print(cc)
  if mc>cc+len(set(i))-1:
    mc=cc+len(set(i))-1
print(mc)

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
import itertools

h, w, k = map(int, input().split())
s = [['0' for i in range(w)] for j in range(h)]

for i in range(h):
  s[i] = input()

cnt = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
  cnt[i][0] = int(s[i][0]) + (0 if i == 0 else cnt[i - 1][0])

for i in range(w):
  cnt[0][i] = int(s[0][i]) + (0 if i == 0 else cnt[0][i - 1])

for i in range(1, h):
  for j in range(1, w):
    cnt[i][j] = cnt[i - 1][j] + cnt[i][j - 1] - cnt[i - 1][j - 1] + int(s[i][j])

num = [i for i in range(h - 1)]
ans = 99999
for i in range(0, h):
  for v in itertools.combinations(num, i):
    n = list(v)
    n.append(h - 1)
    
    _ans = i
    _left = -1
    for j in range(w):
      for _k in range(len(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:
          _left = j
          _ans += 1
          break
    ans = min(ans, _ans)

print(ans)

import itertools

h, w, k = map(int, input().split())
s = [['0' for i in range(w)] for j in range(h)]

for i in range(h):
  s[i] = input()

cnt = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
  cnt[i][0] = int(s[i][0]) + (0 if i == 0 else cnt[i - 1][0])

for i in range(w):
  cnt[0][i] = int(s[0][i]) + (0 if i == 0 else cnt[0][i - 1])

for i in range(1, h):
  for j in range(1, w):
    cnt[i][j] = cnt[i - 1][j] + cnt[i][j - 1] - cnt[i - 1][j - 1] + int(s[i][j])

num = [i for i in range(h - 1)]
ans = 99999
for i in range(0, h):
  for v in itertools.combinations(num, i):
    n = list(v)
    n.append(h - 1)
    
    _ans = i
    _left = -1
    for j in range(w):
      for _k in range(len(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:
          if j - _left == 1:
            _ans = 99999
            break
          _left = j - 1
          j -= 1
          _ans += 1
          break
    ans = min(ans, _ans)

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
import itertools
H, W, K = map(int, input().split())

S = [0]*H
for i in range(H):
  S[i] = input()
Sdivs = []
mcnt = 1100
for b in itertools.product([0, 1], repeat=H-1):
  start = 0
  end = 1
  Sdivs=[]
  for a in b:
    if a==1:
      Sdivs.append(S[start:end])
      start = end
    end += 1
  Sdivs.append(S[start:end])
  cnt = sum(b)
  ones_cum = [0]*len(Sdivs)
  ones = [0]*len(Sdivs)
  mark1,mark2 = False,False
  ws = [0]
  for w in range(1,W):
    if mark2 == True:
      #print(mark)
      break
    for i,Sdiv in enumerate(Sdivs):
      #print(w)
      for s in Sdiv:
        ones_cum[i] += s[w-1]=='1'
        ones[i] += s[w-1]=='1'
      if ones_cum[i] > K:
        mark1 = True
        if w-1 == ws[-1]:
          mark2 = True
        ws.append(w-1)
      
    if mark1 == True:
      mark1 = False
      ones_cum = ones
    ones = [0]*len(Sdivs)
  if mark2 == True:
    continue
  cnt += len(ws)-1
  mcnt = min(mcnt,cnt)
print(mcnt)
    
    
  
      



from itertools import groupby, accumulate, product, permutations, combinations
def solve():
    H, W, K = map(int, input().split())
    S = [input() for _ in range(H)]
    cum = [[0]*(W+1) for _ in range(H+1)]
    for i in range(1,H+1):
        for j in range(1,W+1):
            cum[i][j]=cum[i-1][j]+cum[i][j-1]-cum[i-1][j-1]+int(S[i-1][j-1])
    ans = 2000
    for p in product([0,1],repeat=H-1):
        line = [0]
        p = list(p)
        cnt = sum(p)
        for i in range(1,H):
            if p[i-1]==1:
                line.append(i)
        line.append(H)
        w_s = 0
        w_e = 1
        b = False
        while w_e <= W:
            for i in range(len(line)-1):
                h_s = line[i]
                h_e = line[i+1]
                white = cum[h_e][w_e]+cum[h_s][w_s]-cum[h_e][w_s]-cum[h_s][w_e]
                if white > K:
                    if w_e == w_s+1:
                        b = True
                        break
                    else:
                        w_s = w_e-1
                        cnt += 1
                        break
            if b==True:
                break
            w_e += 1
        else:
            ans = min(ans,cnt)
    return ans
print(solve())


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
from collections import deque
def main():
    H,W,K = map(int,input().split())
    S = [[int(s) for s in input()]for _ in range(H)]
    ans = 2**60
    for i in range(2**(H-1)):
        aa = 0
        for j in range(H-1):
            if (i>>j)&1 == 1:
                aa+=1
        c = aa
        b = [0 for _ in range(c+1)]
        OK = True
        for j in range(W):
            k = 0
            for h in range(H):
                if S[h][j]:b[k] += 1
                if (i>>j)&1==1:k+=1
            
            ok = True
            for p in b:
                if p > K:ok = False
            if not ok:
                aa += 1
                b = [0]*(c+1)
                k = 0
                for h in range(H):
                    if S[h][j]:b[k] += 1
                    if (i>>j)&1==1:k+=1
            ok = True
            for p in b:
                if p > K:ok = False
            if not ok:OK = False;break                
    if OK:ans = min(ans,aa)
    print(ans)

if __name__ == "__main__":
    main()

def main():
    H,W,K = map(int,input().split())
    S = [input()for _ in range(H)]
    ans = 10**9
    for i in range(2**(H-1)):
        aa = 0
        for j in range(H-1):
            if (i>>j)&1 == 1:
                aa+=1
        c = aa
        b = [0]*(c+1)
        OK = True
        for j in range(W):
            k = 0
            for h in range(H):
                if S[h][j] == "1":b[k] += 1
                if (i>>h)&1==1:k+=1
            
            ok = True
            for p in b:
                if p > K:ok = False
            if not ok:
                aa += 1
                b = [0]*(c+1)
                
                k = 0
                for h in range(H):
                    if S[h][j]=="1":b[k] += 1
                    if (i>>h)&1==1:k+=1
                ok = True
                for p in b:
                    if p > K:ok = False
                if not ok:OK = False;break                
        if OK:ans = min(ans,aa)
    print(ans)

if __name__ == "__main__":
    main()

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
def main():
    from itertools import product
    
    H, W, K = map(int, input().split())
    S = [input() for _ in range(H)]
    S_T = [[int(s[w]) for s in S] for w in range(W)]
    sumS = sum(map(sum, S_T))
    ans = (H - 1) * (W - 1)
    
    if sumS <= K:
        print(0)
    else:
        for i in product([True, False], repeat=H-1):
            cnt = sum(i)
            if cnt >= ans:
                continue
            M = [[0]]
            for j, k in enumerate(i):
                if k:
                    M.append([])
                M[-1].append(j+1)
            A = [0] * len(M)
            for s_t in S_T:
                for l, m in enumerate(M):
                    A[l] += sum(s_t[i] for i in m)
                if any(a > K for a in A):
                    cnt += 1
                    if cnt >= ans:
                        break
                    A = [sum(s_t[i] for i in m) for m in M]
                    if any(a > K for a in A):
                        cnt = ans + 1
                        break
            ans = min(cnt, ans)
        print(ans)

if __name__ == '__main__'
    main()

def main():
    from itertools import product

    H, W, K = map(int, input().split())
    S = [input() for _ in range(H)]
    S_T = [[int(s[w]) for s in S] for w in range(W)]
    sumS = sum(map(sum, S_T))
    ans = (H - 1) * (W - 1)

    if sumS <= K:
        print(0)
    else:
        for i in product([True, False], repeat=H-1):
            cnt = sum(i)
            if cnt >= ans:
                continue
            M = [[0]]
            for j, k in enumerate(i):
                if k:
                    M.append([])
                M[-1].append(j+1)
            A = [0] * len(M)
            for s_t in S_T:
                for l, m in enumerate(M):
                    A[l] += sum(s_t[i] for i in m)
                if any(a > K for a in A):
                    cnt += 1
                    if cnt >= ans:
                        break
                    A = [sum(s_t[i] for i in m) for m in M]
                    if any(a > K for a in A):
                        cnt = ans + 1
                        break
            ans = min(cnt, ans)
        print(ans)

if __name__ == '__main__':
    main()

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
import itertools
import numpy as np

res = 999999999999999999

H, W, K = [int(i) for i in input().split()]
arr = []
for h in range(H):
  arr.append([int(v) for v in input()])

arr = np.vstack(arr)
print(arr)
  
for p in itertools.product([0, 1], repeat = H-1):
  sp = np.zeros((sum(p)+1, W), int)
  row = 0
  sp[0] += arr[0]
  for j in range(H-1):
    if p[j]:
      row += 1
    sp[row] += arr[j+1]
  if np.max(sp) > K:
    continue
  
  sum_arr = np.zeros(len(sp), int)
  cut_cnt = sum(p)
  for c in range(W):
    sum_arr += sp[:, c]
    if max(sum_arr) > K:
      sum_arr = sp[:, c]
      cut_cnt += 1
  if cut_cnt < res:
    res = cut_cnt
print(res)

import itertools
import numpy as np

res = 999999999999999999

H, W, K = [int(i) for i in input().split()]
arr = []
for h in range(H):
  arr.append([int(v) for v in input()])

arr = np.vstack(arr)

for p in itertools.product([0, 1], repeat = H-1):
  if sum(p) > res:
    continue
  sp = np.zeros((sum(p)+1, W), int)
  row = 0
  sp[0] += arr[0]
  for j in range(H-1):
    if p[j]:
      row += 1
    sp[row] += arr[j+1]
  if np.max(sp) > K:
    continue
  
  sum_arr = np.zeros(len(sp), int)
  cut_cnt = sum(p)
  for c in range(W):
    sum_arr += sp[:, c]
    if max(sum_arr) > K:
      sum_arr = sp[:, c]
      cut_cnt += 1
      if cut_cnt > res:
        break
  if cut_cnt < res:
    res = cut_cnt
print(res)

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
def main():
    import sys
    input=sys.stdin.readline
    h,w,k=map(int,input().split())
    S=[]
    for _ in range(h):
        s=list(map(int,list(input().rstrip())))
        S.append(s)
    ans=10**5
    for i in range(2**(h-1)):
        l=[0]
        for j in range(h-1):
            if i&1<<j:
                l.append(l[-1]+1)
            else:
                l.append(l[-1]) 
        ans_=l[-1]
        ll=[0]*h
        for j in range(w):
            for p in range(h):
                ll[l[p]]+=S[p][j]
                if ll[l[p]]>k:
                    ans_+=1
                    ll=[0]*h
        ans=min(ans,ans_)
    print(ans)
if __name__ == '__main__':
    main()

def main():
    import sys
    input=sys.stdin.readline
    h,w,k=map(int,input().split())
    S=[]
    for _ in range(h):
        s=list(map(int,list(input().rstrip())))
        S.append(s)
    ans=10**5
    for i in range(2**(h-1)):
        l=[0]
        for j in range(h-1):
            if i&1<<j:
                l.append(l[-1]+1)
            else:
                l.append(l[-1]) 
        ans_=l[-1]
        ll=[0]*h
        j=0
        flag=0
        while j<w:
            for p in range(h):
                ll[l[p]]+=S[p][j]
            if max(ll)>k and flag==0:
                flag=1
                ans_+=1
                ll=[0]*h
            elif max(ll)>k and flag==1:
                ans_=10**5
                break
            else:
                j+=1
                flag=0
        ans=min(ans,ans_)
    print(ans)
if __name__ == '__main__':
    main()

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
import numpy as np
import itertools
H, W, K = [int(_) for _ in input().split()]
S = np.zeros((H + 1, W + 1), dtype=int)
S[1:, 1:] = [[int(_) for _ in input()] for _ in range(H)]
cum = S.cumsum(axis=0).cumsum(axis=1)
#sum(a,b -> x,y) (1-indexed)
#cum[x][y]+cum[a-1][b-1]-cum[a-1][y]-cum[x][b-1]
ans = 10**10
for bs in itertools.product([True, False], repeat=H - 1):
    bs = [True] + list(bs) + [True]
    idxs = []
    for i, b in enumerate(bs):
        if b:
            idxs += [i]
    cum2 = np.array([cum[i2] - cum[i1] for i1, i2 in zip(idxs, idxs[1:])])
    i = 0
    cnt = sum(bs) - 3
    while i < W:
        i = min(np.searchsorted(c, K + c[i], side='right') for c in cum2)
        cnt += 1
    ans = min(ans, cnt)
print(ans)


from numba import njit
import numpy as np
import itertools
H, W, K = [int(_) for _ in input().split()]
S = np.zeros((H + 1, W + 1), dtype=int)
S[1:, 1:] = [[int(_) for _ in input()] for _ in range(H)]


def solve(H, W, K, S):
    cum = S.cumsum(axis=0).cumsum(axis=1)
    #sum(a,b -> x,y) (1-indexed)
    #cum[x][y]+cum[a-1][b-1]-cum[a-1][y]-cum[x][b-1]
    ans = 10**10
    for bs in itertools.product([True, False], repeat=H - 1):
        bs = [True] + list(bs) + [True]
        idxs = []
        for i, b in enumerate(bs):
            if b:
                idxs += [i]
        cum2 = np.array([cum[i2] - cum[i1] for i1, i2 in zip(idxs, idxs[1:])])
        i = 0
        cnt = sum(bs) - 3
        f = True
        while i < W:
            i2 = min(np.searchsorted(c, K + c[i], side='right') for c in cum2)
            if i2 == i:
                f = False
                break
            i = i2
            cnt += 1
        if f:
            ans = min(ans, cnt)
    print(ans)


solve(H, W, K, S)


import numpy as np
import itertools
H, W, K = [int(_) for _ in input().split()]
S = np.zeros((H + 1, W + 1), dtype=int)
S[1:, 1:] = [[int(_) for _ in input()] for _ in range(H)]
cum = S.cumsum(axis=0).cumsum(axis=1)
#sum(a,b -> x,y) (1-indexed)
#cum[x][y]+cum[a-1][b-1]-cum[a-1][y]-cum[x][b-1]
ans = 10**10
for bs in itertools.product([True, False], repeat=H - 1):
    bs = [True] + list(bs) + [True]
    idxs = []
    for i, b in enumerate(bs):
        if b:
            idxs += [i]
    cum2 = np.array([cum[i2] - cum[i1] for i1, i2 in zip(idxs, idxs[1:])])
    i = 0
    cnt = sum(bs) - 3
    while i < W:
        di = min(
            np.searchsorted(c[i + 1:] - c[i], K, side='right') for c in cum2)
        if di == 0:
            cnt = 10**10
            break
        i += di
        cnt += 1
    ans = min(ans, cnt)
print(ans)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
import numpy as np
H,W,K = list(map(int,input().split()))


S = [0]*H
for i in range(H):
    S[i] = list(map(int,list(input())))
# print(S)
S = np.array(S)
# print(S)
# print(np.sum(S[0:3,0:3]))

# n=0
if np.sum(S) <= K:
    print(0)
    exit()

# n=1
for i in range(1,H):
    # print("i:",i)
    # print(S[:i,:],S[i:,:])
    if np.sum(S[:i,:])<=K and np.sum(S[i:,:])<=K:
        print(1)
        exit()

for i in range(1,W):
    # print("i:",i)
    # print(S[:,:i],S[:,i:])
    if np.sum(S[:,:i])<=K and np.sum(S[:,i:])<=K:
        print(1)
        exit()


import itertools

H, W, K = map(int, input().split())
S = []
for _ in range(H):
    S.append([int(s) for s in input()])
# print(S)

ans = 2000
for t in itertools.product([0, 1], repeat=H - 1):
    
    cnt = t.count(1)
    lst = [[s for s in S[0]]]
    for h in range(H - 1):
        if t[h]: 
            lst.append(S[h + 1])
        else: 
            lst[-1] = [lst[-1][i] + S[h + 1][i] for i in range(W)] 
    L = len(lst)
    # print("lst:",lst)
    # print(cnt,L)
    sum_lst = [0] * L
    for w in range(W):
        
        if max(lst[i][w] for i in range(L)) > K:
            # print("break")
            break
        tmp = [sum_lst[i] + lst[i][w] for i in range(L)]
        # print("w=",w,tmp)
        if max(tmp) > K:
            cnt += 1
            
            sum_lst = [lst[i][w] for i in range(L)]
            # print(sum_lst)
        else:
            sum_lst = tmp
    else: 
        ans = min(ans, cnt)
print(ans)
"""
for t in itertools.product([0, 1], repeat=H - 1):
    print(t)
"""

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
from itertools import accumulate

h,w,k = map(int,input().split())
s = [list(map(int,"".join(input()))) for _ in range(h)]

min_split = 10**10

for i in range(2**(h-1)):
    li = []
    for j in range(h-1):
        if (i >> j)&1:
            li.append(j)
    li.append(h-1)
    lin = [0]*w
    total = []
    for l in range(h):
        for m in range(w):
            lin[m] += s[l][m]
        if l in li:
            total.append(lin)
            lin = [0]*w
    now = 0
    t = len(total)
    count = t-1
    for n in range(t):
        total[n] = list(accumulate(total[n]))
    for o in range(w):
        for p in range(t):
            if total[p][o]-total[p][now] > k:
                now = o
                count += 1
                break
    min_split = min(min_split,count)

print(min_split)

from itertools import accumulate

h,w,k = map(int,input().split())
s = [list(map(int,"".join(input()))) for _ in range(h)]

min_split = 10**10

for i in range(2**(h-1)):
    li = []

    for j in range(h-1):
        if (i >> j)&1:
            li.append(j)
    li.append(h-1)
    lin = [0]*w
    total = []

    over = False

    for l in range(h):
        for m in range(w):
            lin[m] += s[l][m]
            if lin[m] > k:
                over = True
        if l in li:
            total.append(lin)
            lin = [0]*w

    if over:
        continue

    now = 0
    t = len(total)
    count = t-1

    for n in range(t):
        total[n] = [0]+list(accumulate(total[n]))
    for o in range(1,w+1):
        for p in range(t):
            if total[p][o]-total[p][now] > k:
                now = o-1
                count += 1
                break

    min_split = min(min_split,count)

print(min_split)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
# coding: utf-8
import itertools
A = [0]
N, S = list(map(int, input().split()))
A = A + list(map(int, input().split()))   
print(N,S,A)
val = 0
for L in range(1, N+1):
  for R in range(L, N+1):
    A_ = A[L:R+1]
    lists = []
    for n in range(len(A_)):
      for comb in itertools.combinations(A_, n+1):
        lists.append(list(comb))
    for lis in lists:
      _sum = sum(lis)
      if _sum == S:
        val += 1
print(val % 998244353)

# coding: utf-8
import itertools
A = [0]
N, S = list(map(int, input().split()))
A = A + list(map(int, input().split()))   
print(N,S,A)
val = 0
for L in range(1, N+1):
  for R in range(L, N+1):
    A_ = A[L:R+1]
    lists = []
    for n in range(len(A_)):
      for comb in itertools.combinations(A_, n+1):
        lists.append(list(comb))
    for lis in lists:
      _sum = sum(lis)
      if _sum == S:
        val += 1
      if val == 998244353:
        val = 0
print(val)

# coding: utf-8
import numpy as np
mod = 998244353
N, S = list(map(int, input().split()))
A = [0] + list(map(int, input().split()))

dp = np.array([[0 for _ in range(S+1)] for i in range(N+1)])

for k in range(0, N):
  dp[k+1,:] += (2 * dp[k,:] - dp[k-1,:]) % mod
  if S > A[k+1]:
    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
  if A[k+1] <= S:
    dp[k+1,A[k+1]] += k+1

print(dp[N,S] % mod)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from numpy import *
M=998244353
N,S,*A=map(int,open(0).read().split())
a=0
f = np.zeros(S+1, np.int64)
for b in As:
  f[0]+=1
  f[b:] += f[:-b].copy()
  f%=M
  a+=f[S]
print(a%M)

from numpy import *
M=998244353
N,S,*A=map(int,open(0).read().split())
a=0
f=zeros(S+1,int)
for b in A:
  f[0]+=1
  f[b:] += f[:-b].copy()
  f%=M
  a+=f[S]
print(a%M)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline
    import numpy as np

    mod = 998244353

    N, S = map(int, input().split())
    A = list(map(int, input().split()))

    
    polynomial = np.zeros(S+1, int)
    ans = 0
    for i in A:
        polynomial[0] += 1
        polynomial[i:] += polynomial[:-i].copy()
        polynomial %= mod
        ans += polynomial[S]

main()

def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline
    import numpy as np

    mod = 998244353

    N, S = map(int, input().split())
    A = list(map(int, input().split()))

    
    polynomial = np.zeros(S+1, int)
    ans = 0
    for i in A:
        polynomial[0] += 1
        polynomial[i:] += polynomial[:-i].copy()
        polynomial %= mod
        ans += polynomial[S]

    print(ans % mod)

main()

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n, s = map(int, input().split())
    a = list(map(int, input().split()))
    import numpy as np
    dp = np.zeros(s+1, dtype=int)
    dp[0] = 1
    mod = 998244353
    ans = 0
    for i in range(n):
        dp[0] += 1
        dp[a[i]:] += dp[:-a[i]]
        dp%= mod
        ans += dp[-1]
        ans %= mod
    print(ans)



if __name__ == '__main__':
    main()

def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n, s = map(int, input().split())
    a = list(map(int, input().split()))
    import numpy as np
    dp = np.zeros(s+1, dtype=int)
    mod = 998244353
    ans = 0
    for i in range(n):
        dp[0] += 1
        dp[a[i]:] += dp[:-a[i]]
        dp%= mod
        ans += dp[-1]
        ans %= mod
    print(ans)



if __name__ == '__main__':
    main()

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import numpy as np

n, s = map(int, input().split())
aaa = list(map(int, input().split()))

fwd_acc = np.zeros((n + 1, s + 1), dtype=np.int64)
fwd_acc[0][0] = 1

ans = 0
MOD = 998244353
for i, a in enumerate(aaa, start=1):
    fwd_acc[i] = fwd_acc[i - 1]
    fwd_acc[i][0] = i
    if a <= s:
        fwd_acc[i][a:] += fwd_acc[i][:-a]
    ans = (ans + fwd_acc[i - 1][s - a] * (n - i + 1)) % MOD
print(ans)


import numpy as np

n, s = map(int, input().split())
aaa = list(map(int, input().split()))

fwd_acc = np.zeros((n + 1, s + 1), dtype=np.int64)
fwd_acc[0][0] = 1

ans = 0
MOD = 998244353
for i, a in enumerate(aaa, start=1):
    fwd_acc[i] = fwd_acc[i - 1]
    fwd_acc[i][0] = i
    if a <= s:
        fwd_acc[i][a:] = fwd_acc[i][a:] + fwd_acc[i][:-a]
    fwd_acc[i] %= MOD
    ans = (ans + fwd_acc[i][s]) % MOD
    # print(fwd_acc)
    # print(ans)
print(ans)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import sys 
MOD = 10**9 +7
INF = 10**5

def main():
    n,s = map(int,input().split())
    a = list(map(int,input().split()))

    dp = [[0] * (s + 1) for _ in range(n + 1)]
    for i in range(n):
        num = a[i]
        for j in range(1,s + 1):
            dp[i + 1][j] = dp[i][j] + dp[i][j - a[i]]
    
    print(dp[-1][-1])
if __name__=='__main__':
    main()

import sys
sys.setrecursionlimit(10000000)
MOD = 998244353
INF = 10 ** 18

import numpy as np
def main():
    N,S = map(int,input().split())
    A = list(map(int,input().split()))
    
    before = np.zeros(S + 1,np.int64)
    before[0] = 1
    ans = 0
    for a in A:
        now = np.zeros(S + 1,np.int64)
        now += before
        now[a:] += before[:-a]
        ans += now[S]
        ans %= MOD
        now[0] += 1
        now = np.mod(now,MOD)
        before = now
    print(ans)
if __name__ == '__main__':
    main()



Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import numpy as np
n,s=map(int,input().split())
t=np.zeros(s+1)
m=10**9+7
a=list(map(int,input().split()))
ans=0
for i in range(n):
    t[a[i]:]+=t[:-a[i]]
    if a[i]<s:
        t[a[i]]+=i+1
    ans+=t[-1]
    ans%=m
print(int(ans))

n,s=map(int,input().split())
t=[0]*(s+1)
m=998244353
a=list(map(int,input().split()))
ans=0
for i in range(n):
    d=t.copy()
    if a[i]<=s:
        for j in range(a[i],s+1):
            t[j]+=d[j-a[i]]
        t[a[i]]+=i+1
    ans+=t[-1]
    ans%=m
print(int(ans))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import numpy as np

n, s = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353

U = 3010
count = 0
F = np.zeros(U + 1, np.int64)
for a in A:
    F[0] += 1
    
    # FF = F
    # FF[a:] += FF[:-a]
    # FF %= MOD
    # F = FF
    F[a:] += F[:-a].copy()
    F %= MOD # forgot
    count += F[s]
    print(F[0:10])

count %= MOD
print(count)

import numpy as np

n, s = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353

U = 3010
count = 0
F = np.zeros(U + 1, np.int64)
for a in A:
    F[0] += 1
    F[a:] += F[:-a].copy()
    F %= MOD
    count += F[s]

count %= MOD
print(count)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
#!python3

import numpy as np

# input
N, S = list(map(int, input().split()))
A = list(map(int, input().split()))

MOD = 998244353


def add_elements(w, i):
    a = A[i]
    w[a:] += w[:-a]
    if a <= S:
        w[a] += i + 1
    w %= MOD


def main():
    w = np.zeros(S + 1, dtype=int)
    ans = 0
    for i in range(N):
        add_elements(w, i)
        ans = (ans + w[S]) % MOD
        print(i, w)
    
    print(ans)


if __name__ == "__main__":
    main()


#!python3

import numpy as np

# input
N, S = list(map(int, input().split()))
A = list(map(int, input().split()))

MOD = 998244353


def add_elements(w, i):
    a = A[i]
    w[a:] += w[:-a].copy()
    if a <= S:
        w[a] += i + 1
    w %= MOD


def main():
    w = np.zeros(S + 1, dtype=int)
    ans = 0
    for i in range(N):
        add_elements(w, i)
        ans = (ans + w[S]) % MOD
    
    print(ans)


if __name__ == "__main__":
    main()


Verdicts: Wrong Answer

Accepted