結果

問題 No.3015 アンチローリングハッシュ
ユーザー kokoa1046kokoa1046
提出日時 2018-01-31 09:57:37
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 998 bytes
コンパイル時間 100 ms
コンパイル使用メモリ 11,020 KB
実行使用メモリ 15,196 KB
最終ジャッジ日時 2023-08-28 17:27:57
合計ジャッジ時間 4,673 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
14,140 KB
testcase_01 AC 28 ms
9,852 KB
testcase_02 AC 27 ms
9,704 KB
testcase_03 AC 27 ms
9,776 KB
testcase_04 AC 26 ms
9,764 KB
testcase_05 AC 26 ms
9,704 KB
testcase_06 AC 33 ms
10,020 KB
testcase_07 AC 27 ms
9,852 KB
testcase_08 AC 29 ms
9,700 KB
testcase_09 AC 51 ms
9,968 KB
testcase_10 AC 165 ms
9,992 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env pypy3
# -*- coding: utf-8 -*-

import itertools
import random
import string

mydict=dict()
max=1000000

def compute_hash(s, a, b):
    h = 0
    n = len(s)
    for i, c in enumerate(s):
        h += ((ord(c) % b) * pow(a, n - 1 - i, b)) % b
        h %= b
    return h


def generate_random_string(digits, source=string.ascii_lowercase):
    return "".join(random.choice(source) for _ in range(digits))


def cycledetection(a,b):
    for i in range(max):
        #print(i)
        tmp=a**i%b
        #print(tmp)
        if tmp in mydict:
            return 0,mydict[tmp]+i,i
        mydict[tmp]=-i

def main():
    a, b = map(int, input().split())
    s, t,length = cycledetection(a, b)
    #print(s,t,length)
    while True:
        tmp=generate_random_string(length+1)
        if tmp[s]!=tmp[t]:
            break
    print(tmp)
    tmp=list(tmp)
    x=tmp[s]
    y=tmp[t]
    tmp[s]=y
    tmp[t]=x
    #print(mydict)
    print("".join(tmp))


if __name__ == '__main__':
    main()
0