結果

問題 No.1004 サイコロの実装 (2)
ユーザー miya145592miya145592
提出日時 2023-05-20 04:49:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 851 bytes
コンパイル時間 333 ms
コンパイル使用メモリ 82,336 KB
実行使用メモリ 53,808 KB
最終ジャッジ日時 2024-12-21 05:46:13
合計ジャッジ時間 3,724 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

a, b, x, N = map(int, input().split())
nxt = x
X = []
while True:
    nxt = (nxt*a+b)%6
    if nxt in X:
        break
    X.append(nxt)

if len(X)%2==1:
    X = X+X
#print(X)

loop = len(X)*2
cnt = N//loop
m = N%loop

nowT = 0
nowA = 0

cntT = [0, 0]
cntA = [0, 0]

si = 0
if cnt > 0:
    for i in range(loop):
        saiT = X[si%len(X)]+1
        nowT += saiT
        nowT %= 2
        cntT[nowT]+=1
        si += 1
        saiA = X[si%len(X)]+1
        nowA += saiA
        nowA %= 2
        cntA[nowA]+=1
        si+=1

    cntT = [cntT[0]*cnt, cntT[1]*cnt]
    cntA = [cntA[0]*cnt, cntA[1]*cnt]

for i in range(m):
    saiT = X[si%len(X)]+1
    nowT += saiT
    nowT %= 2
    cntT[nowT]+=1
    
    si += 1
    saiA = X[si%len(X)]+1
    nowA += saiA
    nowA %= 2
    cntA[nowA]+=1

    si+=1

scoT = min(cntT)
scoA = min(cntA)
print(scoT, scoA)
0