QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#878311 | #9690. Iron Warrior | ucup-team3646# | TL | 21ms | 9216kb | Python3 | 3.9kb | 2025-02-01 14:44:56 | 2025-02-01 14:44:58 |
Judging History
answer
S=4
def mul(A,B):
C=[[0]*S for i in range(S)]
for i in range(S):
for k in range(i,S):
for j in range(k,S):
C[i][j]+=A[i][k]*B[k][j]
return C
E=[[0]*S for i in range(S)]
for i in range(S):
E[i][i]=1
def matpow(A,k):
if k==0:
return E
if k&1:
return mul(A,matpow(A,k-1))
B=matpow(A,k//2)
return mul(B,B)
MA=[[int(i==j) for j in range(S)] for i in range(S)]
MB=[[int(i==j) for j in range(S)] for i in range(S)]
MC=[[int(i==j) for j in range(S)] for i in range(S)]
MD=[[int(i==j) for j in range(S)] for i in range(S)]
MA[2][3]=5
MB[1][3]=11
MC[0][3]=10
MC[1][2]=1
MD[0][1]=1
MD[1][2]=1
M_CBA=mul(MA,mul(MB,MC))
M_CBD=mul(MD,mul(MB,MC))
M_ABA=mul(MA,mul(MB,MA))
M_AD=mul(MD,MA)
M_CD=mul(MD,MC)
M_BD=mul(MD,MB)
POW_CBA=[M_CBA]
for i in range(1,60):
POW_CBA.append(mul(POW_CBA[-1],POW_CBA[-1]))
POW_CBD=[M_CBD]
for i in range(1,60):
POW_CBD.append(mul(POW_CBD[-1],POW_CBD[-1]))
def calc_CBA(turn):
X=E
for i in range(60):
if (turn>>i)&1:
X=mul(X,POW_CBA[i])
return X
def calc_CBD(turn):
X=E
for i in range(60):
if (turn>>i)&1:
X=mul(X,POW_CBD[i])
return X
def calc(x,y):
return mul(calc_CBD(y),calc_CBA(x))
for _ in range(1):
n=int(input())
if n==1:
print(20)
exit()
ans=0
for t in range(3):
if t!=0 and n>20:
continue
if t==0:
M_ABA=mul(MA,mul(MB,MA))
elif t==1:
M_ABA=mul(MD,mul(MB,MA))
else:
M_ABA=mul(MB,mul(MD,MA))
if n%2==1:
ans=max(ans,mul(MD,mul(calc_CBA(n//2),M_ABA))[0][3])
else:
ans=max(ans,mul(MD,mul(calc_CBA(n//2),M_AD))[0][3])
if n%2==1:
L=-1
R=n//2+1
while 0:
nL=(L+L+R)//3
nR=(L+R+R)//3
vL=mul(calc(nL,n//2-nL),M_ABA)[0][3]
vR=mul(calc(nR,n//2-nR),M_ABA)[0][3]
if vL>vR:
R=nR
else:
L=nL
for i in range(max(0,L),min(R+1,n//2+1)):
ans=max(ans,mul(calc(i,n//2-i),M_ABA)[0][3])
L=-1
R=n//2+1
while R-L>2:
nL=(L+L+R)//3
nR=(L+R+R)//3
vL=mul(M_CD,mul(calc(nL,n//2-nL),M_AD))[0][3]
vR=mul(M_CD,mul(calc(nR,n//2-nR),M_AD))[0][3]
if vL>vR:
R=nR
else:
L=nL
for i in range(max(0,L),min(R+1,n//2+1)):
ans=max(ans,mul(M_CD,mul(calc(i,n//2-i),M_AD))[0][3])
L=-1
R=n//2+1
while R-L>2:
nL=(L+L+R)//3
nR=(L+R+R)//3
vL=mul(M_BD,mul(calc(nL,n//2-nL),M_AD))[0][3]
vR=mul(M_BD,mul(calc(nR,n//2-nR),M_AD))[0][3]
if vL>vR:
R=nR
else:
L=nL
for i in range(max(0,L),min(R+1,n//2+1)):
ans=max(ans,mul(M_BD,mul(calc(i,n//2-i),M_AD))[0][3])
else:
L=-1
R=n//2+1
while R-L>2:
nL=(L+L+R)//3
nR=(L+R+R)//3
vL=mul(calc(nL,n//2-nL),M_AD)[0][3]
vR=mul(calc(nR,n//2-nR),M_AD)[0][3]
if vL>vR:
R=nR
else:
L=nL
for i in range(max(0,L),min(R+1,n//2+1)):
ans=max(ans,mul(calc(i,n//2-i),M_AD)[0][3])
L=-1
R=n//2
while R-L>2:
nL=(L+L+R)//3
nR=(L+R+R)//3
vL=mul(M_CD,mul(calc(nL,n//2-nL-1),M_ABA))[0][3]
vR=mul(M_CD,mul(calc(nR,n//2-nR-1),M_ABA))[0][3]
if vL>vR:
R=nR
else:
L=nL
for i in range(max(0,L),min(R+1,n//2)):
ans=max(ans,mul(M_CD,mul(calc(i,n//2-i-1),M_ABA))[0][3])
L=-1
R=n//2
while R-L>2:
nL=(L+L+R)//3
nR=(L+R+R)//3
vL=mul(M_BD,mul(calc(nL,n//2-nL-1),M_ABA))[0][3]
vR=mul(M_BD,mul(calc(nR,n//2-nR-1),M_ABA))[0][3]
if vL>vR:
R=nR
else:
L=nL
for i in range(max(0,L),min(R+1,n//2)):
ans=max(ans,mul(M_BD,mul(calc(i,n//2-i-1),M_ABA))[0][3])
print(ans)
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 11ms
memory: 9088kb
input:
1
output:
20
result:
ok answer is '20'
Test #2:
score: 0
Accepted
time: 14ms
memory: 9216kb
input:
3
output:
72
result:
ok answer is '72'
Test #3:
score: 0
Accepted
time: 10ms
memory: 9216kb
input:
4
output:
105
result:
ok answer is '105'
Test #4:
score: 0
Accepted
time: 13ms
memory: 9216kb
input:
5
output:
145
result:
ok answer is '145'
Test #5:
score: 0
Accepted
time: 13ms
memory: 9088kb
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: 11ms
memory: 9216kb
input:
8
output:
343
result:
ok answer is '343'
Test #8:
score: 0
Accepted
time: 21ms
memory: 9088kb
input:
486036
output:
13810882446441423
result:
ok answer is '13810882446441423'
Test #9:
score: -100
Time Limit Exceeded
input:
857503