結果

問題 No.1544 [Cherry 2nd Tune C] Synchroscope
ユーザー O2MTO2MT
提出日時 2021-06-11 22:45:18
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 943 bytes
コンパイル時間 312 ms
コンパイル使用メモリ 86,936 KB
実行使用メモリ 77,376 KB
最終ジャッジ日時 2023-08-21 13:31:42
合計ジャッジ時間 10,815 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,224 KB
testcase_01 AC 80 ms
71,280 KB
testcase_02 AC 77 ms
71,052 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 TLE -
testcase_34 WA -
testcase_35 AC 79 ms
71,216 KB
testcase_36 WA -
testcase_37 AC 81 ms
76,364 KB
testcase_38 AC 168 ms
76,364 KB
testcase_39 AC 168 ms
76,112 KB
testcase_40 WA -
testcase_41 AC 167 ms
76,312 KB
testcase_42 WA -
testcase_43 AC 161 ms
76,488 KB
testcase_44 AC 165 ms
76,688 KB
testcase_45 WA -
testcase_46 AC 165 ms
76,320 KB
testcase_47 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def is_ok(x, a, b):
    # 条件を満たすかどうか?問題ごとに定義
    f = False
    num = (N*x+a-b)/M
    if num.is_integer():
      f = True
    return f


def meguru_bisect(ng, ok, a, b):
    '''
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid, a, b):
            ok = mid
        else:
            ng = mid
    return ok
N,M = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
flg = False
p = []
ans = float('inf')
for i in range(N):
  for j in range(M):
    if A[i] == B[j]:
      flg = True
      ans = min(ans,meguru_bisect(0,min(N,M),i,j)*N+i+1)

if flg:
  print(ans)
else:
  print(-1)
0