Problem:


(Please read problem A first. The maximum score you can get by solving this problem B is 1, which will have almost no effect on your ranking.)

Beginner's Guide

Let's first write a program to calculate the score from a pair of input and output. You can know the total score by submitting your solution, or an official program to calculate a score is often provided for local evaluation as in this contest. Nevertheless, writing a score calculator by yourself is still useful to check your understanding of the problem specification. Moreover, the source code of the score calculator can often be reused for solving the problem or debugging your solution. So it is worthwhile to write a score calculator unless it is very complicated.

Problem Statement

You will be given a contest schedule for D days.
For each d=1,2,\ldots,D, calculate the satisfaction at the end of day d.

Input

Input is given from Standard Input in the form of the input of Problem A followed by the output of Problem A.

D
c_1 c_2 \cdots c_{26}
s_{1,1} s_{1,2} \cdots s_{1,26}
\vdots
s_{D,1} s_{D,2} \cdots s_{D,26}
t_1
t_2
\vdots
t_D

The constraints and generation methods for the input part are the same as those for Problem A.

For each d, t_d is an integer satisfying 1\leq t_d \leq 26, and your program is expected to work correctly for any value that meets the constraints.

Output

Let v_d be the satisfaction at the end of day d.
Print D integers v_d to Standard Output in the following format:

v_1
v_2
\vdots
v_D

Sample Input 1

5
86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192
1
17
13
14
13

Sample Output 1

18398
35037
51140
65837
79325

Note that this example is a small one for checking the problem specification. It does not satisfy the constraint D=365 and is never actually given as a test case.

Next Step

We can build a solution (schedule) for this problem in the order of day 1, day 2, and so on. And for every partial solution we have built, we can calculate the goodness (satisfaction) by using the above score calculator. So we can construct the following algorithm: for each d=1,2,\ldots,D, we select the contest type that maximizes the satisfaction at the end of day d. You may have already encountered this kind of "greedy algorithms" in algorithm contests such as ABC. Greedy algorithms can guarantee the optimality for several problems, but unfortunately, it doesn't ensure optimality for this problem. However, even if it does not ensure optimality, we can still obtain a reasonable solution in many cases. Let's go back to Problem A and implement the greedy algorithm by utilizing the score calculator you just implemented!

Greedy methods can be applied to a variety of problems, are easy to implement, and often run relatively fast compared to other methods. Greedy is often the most powerful method when we need to process huge inputs.
We can further improve the score by changing the greedy selection criteria (evaluation function), keeping multiple candidates instead of focusing on one best partial solution (beam search), or using the output of greedy algorithms as an initial solution of other methods.
For more information, please refer to the editorial that will be published after the contest.



Sample input:
5
86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192
1
17
13
14
13


Sample output:
18398
35037
51140
65837
79325

Submission status: Accepted

Solution code:

# 入力
D = int(input())
C = list(map(int, input().split()))
S_2d = []
for i in range(D):
    s_1d = list(map(int, input().split()))
    S_2d.append(s_1d)
T = []
for i in range(D):
    t = int(input())
    T.append(t)

last_days = [0] * 26
tot_score = 0

for i in range(D):
    today_contest = T[i]
    last_days[today_contest - 1] = i + 1
    today_plus = S_2d[i][today_contest - 1]
    today_minus = 0
    for j, c in enumerate(C):
        today_minus += c * (i + 1 - last_days[j])
    tot_score += today_plus - today_minus
    print(tot_score)

Submission status: Accepted

Solution code:
def read_input():
    D = int(input())
    C = input().split()
    C = [int(i) for i in C]
    S = [list(map(int, input().split())) for _ in range(D)]
    T = [int(input()) for _ in range(D)]
    return D, C, S, T


def scoring(S, D, T, C):
    res = []
    last = [0 for _ in range(26)]
    final = 0
    for i in range(D):
        dec = 0
        last[T[i] - 1] = i + 1
        for j in range(26):
            dec += C[j] * (i - last[j] + 1)
        final += S[i][T[i] - 1] - dec
        res.append(final)
    return res


D, C, S, T = read_input()
res = scoring(S, D, T, C)
for x in res:
    print(x)

Submission status: Accepted

Solution code:

def read_input():
    D = int(input())
    C = input().split()
    C = [int(i) for i in C]
    S = [list(map(int, input().split())) for _ in range(D)]
    T = [int(input()) for _ in range(D)]
    return D, C, S, T


def scoring(S, D, T, C):
    res = []
    last = [0 for _ in range(26)]
    final = 0
    for i in range(D):
        dec = 0
        for j in range(26):
            for loc, val in enumerate(T[:i + 1]):
                if val == j + 1:
                    last[j] = loc + 1
            dec += C[j] * (i - last[j] + 1)
        final += S[i][T[i] - 1] - dec
        res.append(final)
    return res


D, C, S, T = read_input()
res = scoring(S, D, T, C)
for x in res:
    print(x)

Submission status: Accepted

Solution code:
NUM_CONTESTS = 26

def main():
    D = int(input())
    c_list = list(map(int, input().split()))
    s_list = [list(map(int, input().split())) for _ in range(D)]

    t_list = [int(input()) for _ in range(D)]
    v_list = calc_score_list(s_list, c_list, t_list)

    for v in v_list:
        print(v)


def calc_score_list(s_list, c_list, t_list):
    last = [-1 for _ in range(NUM_CONTESTS)]
    score_list = []
    score = 0
    for d, t in enumerate(t_list):
        last[t - 1] = d
        score += s_list[d][t - 1] - sum([c * (d - l) for c, l in zip(c_list, last)])
        score_list.append(score)
    return score_list



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
t = [int(input()) for _ in range(d)]

TYPES = 26
history = [-1] * TYPES
satisfaction_level = [0] * (d+1)

def last(day, i):
    if history[i] == -1:
        return 0
    else:
        return history[i]

def satisfaction(day, typ):
    # コンテスト実施記録を更新
    history[typ] = day
    # 満足度の減少
    decrease = sum((c[i]*(day-last(day,i)) for i in range(TYPES)))
    value = s[day-1][typ] - decrease + satisfaction_level[day-1]
    satisfaction_level[day] = value
    return value

for day, typ in enumerate(t):
    print(satisfaction(day+1, typ-1))

Submission status: Accepted

Solution code:
class Heruistics:
    allpref = [] #allpref[day][contest]
    donelist = [0]*26
    resultlist = []
    contestlist = []

    def __init__(self,days):
        self.days = days
        self.clast = list(map(int,input().split()))
        for i in range(days):
            self.allpref.append(list(map(int,input().split())))

    def scoring(self,contlist):
        result = 0
        for i in range(self.days):
            cont = contlist[i]
            self.donelist[cont-1] = i+1
            zanen = sum([self.clast[j]*((i+1)-self.donelist[j]) for j in range(26)])

            result += self.allpref[i][cont-1] - zanen
            self.resultlist.append(result)

b_heru = Heruistics(int(input()))
for i in range(b_heru.days):
    b_heru.contestlist.append(int(input()))

b_heru.scoring(b_heru.contestlist)

for result in b_heru.resultlist:
    print(result)

Submission status: Accepted

Solution code:
D=int(input())
c=[None]+list(map(int, input().split()))
s=[None]+[list(map(int, input().split())) for _ in range(D)]
T=[None]+[int(input()) for _ in range(D)]

lastdi=[None]+[0]*26

v=0

for i in range(1, D+1):
  v+=s[i][T[i]-1]
  lastdi[T[i]]=i
  for x in range(1, 27):
    v-=(i-lastdi[x])*c[x]
    
  print(v)

Submission status: Accepted

Solution code:
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

D = INT()
C = LIST()
S = [[]] * D
for i in range(D):
    S[i]  = LIST()
T = [t-1 for t in LIST(D)]
M = 26

last = [0] * M
ans = 0
for i, t in enumerate(T):
    ans += S[i][t]
    for j in range(M):
        last[j] += 1
    last[t] = 0
    for j in range(M):
        ans -= C[j] * last[j]
    print(ans)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

d = inp()
c = inpl()
s = [inpl() for _ in range(d)]
res = 0
last = [0]* 26
for day in range(d):
    t = inp(); t -= 1
    res += s[day][t]
    for i in range(26):
        last[i] += 1
        if i == t:
            last[t] = 0
        res -= c[i] * last[i]
    print(res)

Submission status: Accepted

Solution code:
def down(d, last, c):
    result = 0
    for i in range(26):
        result += c[i] * (d - last[i])
    return result


def main():
    D = int(input())
    C = [int(c) for c in input().split()]

    S = [0] * D

    for d in range(D):
        S[d] = [int(s) for s in input().split()]

    last = [0] * 26

    score = 0
    scores = [0] * D
    for d in range(D):
        t = int(input()) - 1

        score += S[d][t]
        last[t] = d + 1

        score -= down(d + 1, last, C)
        scores[d] = score

    for score in scores:
        print(score)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
D = int(input())

c = list(map(int,input().split()))

S = []
for i in range(D):
  s = list(map(int,input().split()))
  S.append(s)

T = []
for i in range(D):
  t = int(input())
  T.append(t)

rh = [[0]*26 for i in range(D)]

ans = 0
for i in range(1,D+1):
  m = S[i-1][T[i-1]-1]
  tot = 0
  rh[i-1][T[i-1]-1] += 1 
  for j in range(26):
    last = 0
    for k in range(D):
        if rh[k][j] == 1:
          last = (k+1)
    tot += (c[j]*(i - last))
  ans += m-tot
  print(ans)

Submission status: Accepted

Solution code:
import numpy

D = int(input())
c_list = list(map(int, input().split()))
s_list = []

for i in range(D):
    s_list.append(list(map(int, input().split())))

t_list = []
score = 0
past_list = [0] * 26

for i in range(D):
    t_list.append(int(input()) - 1)

for i in range(D):
    for j in range(26):
        if(t_list[i] == j):
            score += s_list[i][j]
            past_list[j] = i + 1
        else:
            score -= c_list[j] * (i + 1 - past_list[j])
    print(score)

Submission status: Accepted

Solution code:
d=int(input())
*c,=map(int, input().split())
s=[]
for _ in range(d):
    *si,=map(int, input().split())
    s.append(si)
t=[int(input())-1 for _ in range(d)]
last=[-1]*26
smx=0
ss=0
for i in range(d):
    ss+=s[i][t[i]]
    last[t[i]]=i
    for j in range(26):
        ss-= c[j]*(i-last[j])
    print(ss)

Submission status: Accepted

Solution code:
D = int(input())
c = [*map(int, input().split())]
s = [0] + [[*map(int, input().split())] for _ in range(D)]
t = [0] + [int(input()) for _ in range(D)]

v = 0
last = [0] * 26
for d in range(1, D+1):
    select = t[d] - 1
    v += s[d][select]
    last[select] = d
    v -= sum(c[i] * (d - last[i]) for i in range(26))
    print(v)

Submission status: Accepted

Solution code:
import numpy as np

D=int(input())
C=np.array(list(map(int,input().split())))
S=[]
for _ in range(D):
    S.append(list(map(int,input().split())))
T=[int(input()) for _ in range(D)]

def last(d):
    l=np.zeros(26,int)
    for i in range(d):
        l[T[i]-1]=i+1
    return l

def decrease(d):
    return np.dot(C,(d-last(d)))



manzoku=0
res=[]
for i in range(D):
    manzoku+=S[i][T[i]-1]
    manzoku-=decrease(i+1)
    res.append(manzoku)

for x in res:
    print(x)

Submission status: Accepted

Solution code:
D = int(input())
C = list(map(int, input().split()))

S = [list(map(int, input().split())) for _ in range(D)]

contest = [0 for _ in range(26)]
ans = 0

for i in range(D):
    t = int(input())
    contest[t-1] = i+1
    ans += S[i][t-1]
    for j, con in enumerate(contest):
        if con:
            ans -= C[j]*(i+1-con)
        else:
            ans -= C[j]*(i+1)
    print(ans)

Submission status: Accepted

Solution code:
D = int(input())
c = list(map(int,input().split()))
s = [ [0 for j in range(26)] for i in range(D)]
for i in range(D):
    tmp = list(map(int,input().split()))
    for j in range(26):
        s[i][j] = tmp[j]
t = []
for i in range(D):
    t.append(int(input()))


v = [0] * D
last = [0] * 26
sat = 0
for d in range(D):
    j = t[d] - 1
    sat += s[d][j]
    last[j] = d+1
    for j in range(26):
        sat -= c[j] * ( d + 1 - last[j] )
    v[d] = sat

for i in range(D):
    print(v[i])

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

D = i()
c = l()
s = [l() for _ in range(D)]
t = [i() for _ in range(D)]
last = [0]*26
ans = 0
for i in range(D):
    last[t[i]-1] = i+1
    ans += s[i][t[i]-1]
    for j in range(26):
        ans -= c[j]*(i+1-last[j])
    print(ans)

Submission status: Accepted

Solution code:
import sys
import math
from collections import deque
import heapq
import itertools
from decimal import Decimal
import bisect
from operator import itemgetter
MAX_INT = int(10e18)
MIN_INT = -MAX_INT
mod = 1000000000+7
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def tami(date, LastDay, type, score):
  res = score
  res += s[date-1][type]
  for i in range(26):
    if i == type:
      continue
    res -= (date - LastDay[i]) *c[i]
  return res

D = I()
c = IL()
s = [IL() for i in range(D)]
ans = [I() for i in range(D)]

LastDay = [0]*26
score = 0
for d in range(D):
  score = tami(d+1, LastDay, ans[d]-1, score)
  LastDay[ans[d]-1] = d+1
  print(score)

Submission status: Accepted

Solution code:
D=int(input())
c=list(map(int,input().split()))
s=[]
for i in range(D):
    s.append(list(map(int,input().split())))

last=[0]*26
ans=0
for d in range(1,D+1):
    t=int(input())
    last[t-1]=d
    temp=0
    for i in range(26):
        if i==t-1:
            temp=s[d-1][t-1]
        else:
            temp=-c[i]*(d-last[i])
        ans+=temp
    print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

d= int(input())

C = list(map(int,input().split()))
CB = [0 for i in range(len(C))]

c = sum(C)

total = 0

#print(c,C,CB)
L = []

for i in range(d):
    L.append(list(map(int,input().split())))

#print(L)

T = []

for i in range(d):
    T.append(int(input()))

#print(T)

def cnt(CB,t):
    for i in range(len(CB)):
        if i != t-1:
            CB[i] += 1
        else:
            CB[i] = 0
    
    return CB

def sumA(C,CB):
    a = 0
    for i in range(len(CB)):
        a += CB[i]*C[i]
    return a

for i in range(len(T)):
    CB = cnt(CB,T[i])
    total += L[i][T[i]-1] - sumA(C,CB)
    print(total)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
import numpy as np
# stdin = open("sample.txt")

MOD = 1000000007
INF = float('inf')
alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

def keta(kazu): # 入力されたintを桁ごとに分解，リストで出力
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers): # 最小公倍数
    return reduce(math.gcd, numbers)

def combination(m,n): # mCn
    
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

def pow_k(x,n):  # (x**n)の計算の高速化
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
    return K * x

def fact(n): # nの素因数分解の結果を辞書で出力 fuct(24) → {2: 3, 3: 1}
    arr = {}
    temp = n
    for i in range(2,int(n**0.5)+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr[i] = cnt
    if temp != 1:
        arr[temp] = 1
    if arr == {}:
        arr[n] = 1
    return arr

def main():
    d = int(stdin.readline().rstrip())
    c = list(map(int,[int(x) for x in stdin.readline().rstrip().split()]))
    table = []
    last = [0]*26
    score = 0
    for _ in range(d):
        table.append(list(map(int,[int(x) for x in stdin.readline().rstrip().split()])))
    for D in range(d):
        go = int(stdin.readline().rstrip()) - 1
        for i in range(26):
            if i == go:
                score += table[D][i]
                last[i] = D+1
                # print(table[D][i])
            else:
                score -= c[i]*(D+1-last[i])
                # print(c[i]*(D+1-last[i]))
        print(score)
main()

Submission status: Accepted

Solution code:
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
t = [int(input()) for _ in range(d)]

last = [[0] * d for _ in range(26)]  # 26xd

ans = 0
for i in range(d):
    type = t[i]  # 1~26
    contest = c[type-1]
    satisfy = s[i][type-1]
    ans += satisfy
    last[type-1][i:] = [i+1] * (d-i)

    for j in range(26):
        ans -= c[j] * ((i+1)-last[j][i])
    print(ans)

Submission status: Accepted

Solution code:
D=int(input())
C=list(map(int,input().split()))
S=[list(map(int,input().split())) for i in range(D)]
T=[int(input()) for i in range(D)]
result=0
last=[0 for i in range(26)]

for i in range(D):
    t=T[i]-1
    last[t]=-1
    result+=S[i][t]
    for j in range(26):
        last[j]+=1
        result-=last[j]*C[j]
    print(result)

Submission status: Accepted

Solution code:
def scoring(last, c, s, t, d, score):
    score += s[d][t[d]-1]
    for i in range(len(c)):
        score -= c[i] * (d+1 - last[d][i])
    return score

score = 0
D = int(input())
c = [int(i) for i in input().split()]
s = []
for i in range(D):
    s.append([int(i) for i in input().split()])
t = []
for i in range(D):
    t.append(int(input()))

last = [[0 for i in range(len(c))] for j in range(D+1)] # last[d][i]

for d in range(D):
    last[d][t[d]-1] = d+1

    for i in range(len(c)):
        last[d+1][i] = last[d][i]

    score = scoring(last, c, s, t, d, score)
    print(score)

Submission status: Accepted

Solution code:
D = int(input())
c = list(map(int, input().split()))
s = [[]]
for _ in range(D):
  s.append(list(map(int, input().split())))

lasts = [0 for i in range(len(c))]
ans = 0
for d in range(1, D+1):
  t = int(input()) - 1
  lasts[t] = d
  ans += s[d][t]
  for i in range(len(c)):
    ans -= c[i] * (d - lasts[i])
  print(ans)

Submission status: Accepted

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


def satisfaction(d, last, c):
    res = 0
    for i in range(26):
        res += c[i] * (d - last[i])
    return res


def main():
    d = I()
    c = LI()
    s = LIR(d)
    t = IR(d)
    last = [0] * 26
    satis = 0
    for day in range(d):
        j = t[day] - 1
        last[j] = day + 1
        satis += s[day][j]
        satis -= satisfaction(day + 1, last, c)
        print(satis)


main()

Submission status: Accepted

Solution code:
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]
T = [int(input())-1 for _ in range(D)]

last = [0] * 26
score = 0
for d in range(D):
    v = T[d]
    score += S[d][v]
    for i in range(26):
        if i == v:
            last[i] = 0
        else:
            last[i] += 1
        score -= C[i] * last[i]
    print(score)

Submission status: Accepted

Solution code:
d = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(d)]
T = [int(input())-1 for _ in range(d)]

last = [0] * 26
ans = 0
for i in range(d):
    v = T[i]
    ans += S[i][v]
    for j in range(26):
        if j == v:
            last[j] = 0
        else:
            last[j] += 1
        ans -= C[j] * last[j]
    print(ans)

Submission status: Accepted

Solution code:
D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(D)]
t = [int(input()) for i in range(D)]
tmp = 0
last = [0]*(26)
v = [0]*(D+1) #満足度これだけi=日付他のはi-1=日付


for i in range(D):
	tmp = 0
	tmp += v[i] + s[i][(t[i]-1)]
	last[t[i]-1] = (i+1)
	for j in range(26):
		tmp -= c[j] * (i+1 - last[j]) 
	v[i+1]=tmp
#print(v)
for i in range(1,D+1):
	print(v[i])

Submission status: Accepted

Solution code:
#d=日数, c=満足低下度, s=満足上昇度, t=コンテストの日程 
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(d)]
t = [int(input()) for j in range(d)]
last = [0 for i in range(26)]
#print(c)
res = 0
count = 0
#while count != len(t):
for day in range(d):
  res += s[day][t[day]-1]
  last[t[day]-1] = day+1
  #print(last)
  #print(c[last[t[day]-1]])
  for i in range(26):
    #print(c[i] * (day + 1 - last[i]))
    res -= c[i] * (day + 1 - last[i])
  print(res)

Submission status: Accepted

Solution code:
#Scoring
import numpy as np
D = int(input())
C = np.array(list(map(int, input().split())))
S = np.zeros((D,26),int)
for i in range(D):
    S[i] = list(map(int, input().split()))

t = np.zeros(D,int)
for i in range(D):
    t[i] = int(input())

score = int(0)
ld = -np.ones(26,int)
tscore = np.zeros(26,int)
for i in range(D):
    cid = t[i]-1
    ld[cid] = i
    score -= np.sum(C*(i-ld))
    score += S[i,cid]
    print(score)

Submission status: Accepted

Solution code:
D = int(input())
C = list(map(int, input().split()))
S = [0] * D
for i in range(D):
  S[i] = list(map(int, input().split()))
         
         
t = [0] * D
for i in range(D):
  t[i] = int(input())
  
last = [0] * (26)
score = 0
for i in range(1, D + 1):
  now = t[i - 1] - 1
  score += S[i - 1][now]
  last[now] = i
  for j in range(26):
    score -= C[j] * (i - last[j])
    
  print(score)

Submission status: Accepted

Solution code:
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
t = [int(input()) for _ in range(d)]

last = [0] * 26
ans = 0
for di in range(d):
    ans += s[di][t[di] - 1]
    last[t[di] - 1] = di + 1
    ans -= sum(c[i] * (di + 1 - last[i]) for i in range(26))
    print(ans)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline

D = int(readline())
C = list(map(int,readline().split()))
S = [None] * D
for i in range(D):
  s = list(map(int,readline().split()))
  S[i] = s
  
def calc_score(arr):
  point = 0
  last_submit = [-1] * 26
  for i in range(len(arr)):
    point += S[i][arr[i]]
    last_submit[arr[i]] = i
    for j in range(len(last_submit)):
      point -= (i - last_submit[j]) * C[j]
    print(point)
  return point

T = [None] * D
for i in range(D):
  T[i] = int(readline()) - 1
  
ans = calc_score(T)

Submission status: Accepted

Solution code:
d = int(input())
*C, = map(int, input().split())
S = [list(map(int, input().split())) for i in range(d)]
T = [int(input()) - 1 for i in range(d)]
L = [-1 for j in range(26)]
score = 0
for i in range(d):
    score += S[i][T[i]]
    L[T[i]] = i
    score -= sum([C[j] * (i - L[j]) for j in range(26)])
    print(score)

Submission status: Accepted

Solution code:
import numpy as np

d = int(input())    # Day
C = list(map(int, input().split()))  # 満足度の減少係数
S = []  # 各日にち、各タイプの満足度
T = []  # d日目の開催タイプ
L = [0] * 26    # 各コンテストが開催された最後の日付

for _ in range(d):
    S.append(list(map(int, input().split())))  # Si,d type_iをdayDに開いた時の満足度 [5, 26]

for _ in range(d):
    T.append(int(input()))

# print("d:", d)
# print("C:", C)
# print("S:", S)
# print("T:", T)

sat = 0
S = np.array(S)

for i in range(d):
    con_type = T[i]
    # print("開催するコンテストタイプ：", con_type)
    complain = 0
    L[con_type - 1] = i + 1     # 最終開催日の更新
    for j in range(26):
        # print("{} + {} * ({} - {})".format(complain, C[j], i+1, L[j]))
        complain = complain + C[j] * (i + 1 - L[j])

    # print("complain:", complain)
    # print("S:", S[i][con_type - 1])
    # print("satの計算: {} + {} - {}".format(sat, S[i][con_type - 1], complain ))

    sat = sat + S[i][con_type - 1] - complain

    print(sat)

Submission status: Accepted

Solution code:
import copy
D = int(input())
c = list(map(int, input().split()))
s = []
for _ in range(D):
  s.append(list(map(int, input().split())))
t = []
for _ in range(D):
  t.append(int(input()))
u = [] # last(d,i)
x = [0] * 26
u.append(x)
for i in range(D):
  v = copy.deepcopy(u)
  y = v[-1]
  y[t[i]-1] = i+1
  u.append(y)
del u[0]

ans = 0
for i in range(D):
  ans += s[i][t[i]-1]
  for j in range(26):
    ans -= c[j] * ((i+1) - u[i][j]) 
  print(ans)

Submission status: Accepted

Solution code:
D = int(input())
clist = list(map(int, input().split()))
slist = [list(map(int, input().split())) for _ in range(D)]
tlist = [int(input()) for _ in range(D)]
zlist = []
dlist = [0] * 26
ans = 0
'''
print(sum(clist))
print('--------------')
print(slist[0][0])
print(slist[1][16])
print(clist[16])

print('--------------')
'''
for i in range(D):
  #print(slist[i],tlist[i]-1)
  zlist.append(clist[tlist[i]-1] * ((i+1) - dlist[tlist[i]-1]))
  dlist[tlist[i]-1] = i+1
  ans += slist[i][tlist[i]-1] - ((i+1) * sum(clist)) + sum(zlist)
  print(ans)

Submission status: Accepted

Solution code:
D = int(input())

c = list(map(int, input().split()))

#増加する満足度表 [日数][種類]
s = []
for i in range(D):
    l = list(map(int, input().split()))
    s.append(l)

#開催するコンテストタイプ[日数]
t = [int(input()) for j in range(D)]

last = [0]*26 #最後に開催した日

SP = 0
dis = 0

for k in range(D): #満足度の計算
    SP += s[k][t[k]-1]
    last[t[k]-1] = k + 1 #開催日の更新
    for m in range(26):
        SP -= c[m] * (k + 1 - last[m])
    print(SP)

Submission status: Accepted

Solution code:
d = int(input())
C = list(map(int, input().split()))
S = []
for _ in range(d):
    S.append(list(map(int, input().split())))
v = 0
LDs = [0 for _ in range(26)]
for i in range(d):
    t = int(input()) - 1
    R = [(i + 1 - LDs[j]) * C[j] for j in range(26)]
    del R[t]
    v += S[i][t] - sum(R)
    LDs[t] = i + 1
    print(v)

Submission status: Accepted

Solution code:
import numpy as np
import numba


@numba.njit('i4[:](i4, i4[:], i4[:, :], i4[:])')
def solve(dd, c_arr, s_arr, t_arr):
    last_d = np.zeros(26, dtype=np.int32) - 1
    score = 0
    score_arr = np.zeros(dd, dtype=np.int32)
    for d in range(dd):
        score += s_arr[d, t_arr[d] - 1]
        last_d[t_arr[d] - 1] = d
        score -= (c_arr * (d - last_d)).sum()
        score_arr[d] = score
    return score_arr


def main():
    d = np.int32(input())
    c_arr = np.array(list(map(int, input().split()))).astype(np.int32)
    s_arr = np.array([list(map(int, input().split())) for _ in range(d)]).astype(np.int32)
    t_arr = np.array([int(input()) for _ in range(d)]).astype(np.int32)
    res = solve(d, c_arr, s_arr, t_arr)
    for r in res:
        print(r)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
D=int(input())
C=list(map(int,input().split()))
S=list()
for i in range(D):
  S.append(list(map(int,input().split())))
t=list()
for i in range(D):
  t.append(int(input()))

M=0
di=[0]*26
for d in range(D):
  for i in range(26):
    if i==t[d]-1:
      di[i]=0
    else:
      di[i]+=1
  M+=S[d][t[d]-1]
  for i in range(26):
    M-=C[i]*(di[i])
  print(M)

Submission status: Accepted

Solution code:
D = int(input())
c = list(map(int, input().split()))
s_tbl = [list(map(int, input().split())) for _ in range(D)]
ans = 0
last = [0] * 26

for d in range(1, D+1):
    t = int(input()) - 1
    c_sum = 0
    for i in range(26):
        c_sum = c_sum + c[i] * (d-last[i])
    ans = ans + s_tbl[d-1][t] + (-c_sum) + c[t] * (d-last[t])
    last[t] = d
    print(ans)

Submission status: Accepted

Solution code:
D=int(input())
c=[int(x) for x in input().split()]
s=[[0]*i for i in range(D)]
t=[]
last_d=[0]*26
for i in range(D):
  s[i]=[int(x) for x in input().split()]
for i in range(D):
  t.append(int(input()))

v=0
for i in range(D):
  a=0
  for j in range(26):
    if j!=t[i]-1:
      n=i+1-last_d[j]
      a+=c[j]*n
  v=v+s[i][t[i]-1]-a
  print(v)
  last_d[t[i]-1]=i+1