QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#878716 | #9690. Iron Warrior | ucup-team5243# | TL | 200ms | 9216kb | Python3 | 1.5kb | 2025-02-01 17:02:45 | 2025-02-01 17:02:46 |
Judging History
answer
def mat_mul(a, b) :
I, J, K = len(a), len(b[0]), len(b)
c = [[0] * J for _ in range(I)]
for i in range(I) :
for j in range(J) :
for k in range(K) :
c[i][j] += a[i][k] * b[k][j]
return c
def mat_pow(x, n):
y = [[0] * len(x) for _ in range(len(x))]
for i in range(len(x)):
y[i][i] = 1
while n > 0:
if n & 1:
y = mat_mul(x, y)
x = mat_mul(x, x)
n >>= 1
return y
N = int(input())
if N <= 3:
print([20,42,72,105,145,208,248,343,393,517,569,749,809,1022,1092][N-1])
exit()
body = [[1,0,1,0],[5,1,0,0],[0,0,1,0],[0,0,0,1]]
pommel = [[1,0,0,0],[5,1,0,0],[0,0,1,0],[0,0,10,1]]
shrug = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[11,0,0,1]]
rage = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,1,0,1]]
def solve(arg):
now = [[0,0,0,1]]
if N%2 == 1:
now = mat_mul(now,mat_mul(mat_mul(rage,body),mat_mul(pommel,shrug)))
cnt = (N-3)//2
else:
now = mat_mul(now,mat_mul(rage,shrug))
cnt = (N-2)//2
if arg > cnt:
return [[0,0,-10**18,0]]
X = mat_mul(rage,mat_mul(pommel,shrug))
Y = mat_mul(body,mat_mul(pommel,shrug))
now = mat_mul(now, mat_pow(X,arg))
now = mat_mul(now, mat_pow(Y,cnt-arg))
now = mat_mul(now,body)
now = mat_mul(now,pommel)
now = mat_mul(now,body)
return (now)
ans = []
for i in range(N//5-10000,N//5+10000):
if i >= 0:
ans.append(solve(i)[0][2])
print(max(ans))
詳細信息
Test #1:
score: 100
Accepted
time: 9ms
memory: 8832kb
input:
1
output:
20
result:
ok answer is '20'
Test #2:
score: 0
Accepted
time: 8ms
memory: 8832kb
input:
3
output:
72
result:
ok answer is '72'
Test #3:
score: 0
Accepted
time: 89ms
memory: 9088kb
input:
4
output:
105
result:
ok answer is '105'
Test #4:
score: 0
Accepted
time: 200ms
memory: 8960kb
input:
5
output:
145
result:
ok answer is '145'
Test #5:
score: 0
Accepted
time: 87ms
memory: 9216kb
input:
6
output:
208
result:
ok answer is '208'
Test #6:
score: 0
Accepted
time: 198ms
memory: 9088kb
input:
7
output:
248
result:
ok answer is '248'
Test #7:
score: 0
Accepted
time: 86ms
memory: 9088kb
input:
8
output:
343
result:
ok answer is '343'
Test #8:
score: -100
Time Limit Exceeded
input:
486036