QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#878713 | #9690. Iron Warrior | ucup-team5243# | WA | 87ms | 9088kb | Python3 | 1.5kb | 2025-02-01 17:02:27 | 2025-02-01 17:02:27 |
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-100,N//5+100):
if i >= 0:
ans.append(solve(i)[0][2])
print(max(ans))
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 9ms
memory: 8832kb
input:
1
output:
20
result:
ok answer is '20'
Test #2:
score: 0
Accepted
time: 12ms
memory: 8832kb
input:
3
output:
72
result:
ok answer is '72'
Test #3:
score: 0
Accepted
time: 11ms
memory: 8960kb
input:
4
output:
105
result:
ok answer is '105'
Test #4:
score: 0
Accepted
time: 10ms
memory: 8960kb
input:
5
output:
145
result:
ok answer is '145'
Test #5:
score: 0
Accepted
time: 13ms
memory: 8960kb
input:
6
output:
208
result:
ok answer is '208'
Test #6:
score: 0
Accepted
time: 13ms
memory: 9088kb
input:
7
output:
248
result:
ok answer is '248'
Test #7:
score: 0
Accepted
time: 10ms
memory: 8960kb
input:
8
output:
343
result:
ok answer is '343'
Test #8:
score: -100
Wrong Answer
time: 87ms
memory: 9088kb
input:
486036
output:
13779748168195543
result:
wrong answer expected '13810882446441423', found '13779748168195543'