結果
問題 | No.2968 Final MIGISITA Strike |
ユーザー | 👑 rin204 |
提出日時 | 2024-11-16 22:54:08 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,133 bytes |
コンパイル時間 | 2,360 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 121,352 KB |
最終ジャッジ日時 | 2024-11-16 22:54:40 |
合計ジャッジ時間 | 26,301 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
52,736 KB |
testcase_01 | AC | 39 ms
52,352 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 40 ms
52,608 KB |
testcase_08 | WA | - |
testcase_09 | AC | 39 ms
52,864 KB |
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 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | WA | - |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | WA | - |
testcase_51 | WA | - |
testcase_52 | WA | - |
testcase_53 | WA | - |
testcase_54 | WA | - |
testcase_55 | WA | - |
testcase_56 | WA | - |
testcase_57 | WA | - |
testcase_58 | WA | - |
testcase_59 | WA | - |
testcase_60 | WA | - |
testcase_61 | WA | - |
testcase_62 | WA | - |
testcase_63 | WA | - |
testcase_64 | AC | 43 ms
52,352 KB |
testcase_65 | WA | - |
testcase_66 | WA | - |
ソースコード
def ext_gcd(a, b): """ return (x, y, gcd(a, b)) s.t. ax + by = gcd(a, b) """ if b == 0: return 1, 0, a else: y, x, g = ext_gcd(b, a % b) return x, y - (a // b) * x, g from math import gcd MOD = 998244353 h, w, n, m, s, c, X, Y = map(int, input().split()) pos = [] for _ in range(n): x, y, a = map(int, input().split()) y = w - y pos.append((x, y, a)) for _ in range(m): x, y, a = map(int, input().split()) y = w - y pos.append((x, y, -a)) Y = w - Y lcm = 4 * h * w // gcd(2 * h, 2 * w) add = [] c0 = 0 c1 = 0 for x, y, a in pos: x_, y_, g = ext_gcd(2 * h, 2 * w) diff = (X - Y) - (x - y) if diff % g == 0: xx = x_ * (diff // g) to_x = x + xx * 2 * h add.append(((to_x - X) % lcm, a)) if a > 0: c0 += 1 else: c1 += 1 diff = (X - Y) - (x - (2 * w - y)) if diff % g == 0: xx = x_ * (diff // g) to_x = x + xx * 2 * h add.append(((to_x - X) % lcm, a)) if a > 0: c0 += 1 else: c1 += 1 diff = (X - Y) - ((2 * h - x) - y) if diff % g == 0: xx = x_ * (diff // g) to_x = 2 * h - x + xx * 2 * h add.append(((to_x - X) % lcm, a)) if a > 0: c0 += 1 else: c1 += 1 diff = (X - Y) - ((2 * h - x) - (2 * w - y)) if diff % g == 0: xx = x_ * (diff // g) to_x = 2 * h - x + xx * 2 * h add.append(((to_x - X) % lcm, a)) if a > 0: c0 += 1 else: c1 += 1 add.sort(key=lambda x: x[0]) tot = 0 min_ = 0 add.append((lcm, 0)) bt = -1 for t, x in add: tot -= (t - 1 + X) // h * c tot -= (t - 1 + Y) // w * c tot += (bt + X) // h * c tot += (bt + Y) // w * c min_ = min(min_, tot) tot += x bt = t if s + min_ > 0 and tot >= 0: print(-1) exit() loop = max(0, (s + min_) // abs(tot)) c0 *= loop c1 *= loop s += loop * tot bt = -1 for t, x in add: diff = 0 diff -= (t - 1 + X) // h * c diff -= (t - 1 + Y) // w * c diff += (bt + X) // h * c diff += (bt + Y) // w * c bt = t if diff + s <= 0: lef = bt rig = t while rig - lef > 1: mid = (rig + lef) // 2 diff = 0 diff -= (mid - 1 + X) // h * c diff -= (mid - 1 + Y) // w * c diff += (bt + X) // h * c diff += (bt + Y) // w * c if diff + s <= 0: rig = mid else: lef = mid xx = (X + rig) % (2 * h) yy = (Y + rig) % (2 * w) if xx >= h: xx = 2 * h - xx if yy >= w: yy = 2 * w - yy yy = w - yy print(xx, yy, c0, c1) break s += diff s += x if x > 0: c0 += 1 else: c1 += 1 if s <= 0: xx = (X + t) % (2 * h) yy = (Y + t) % (2 * w) if xx >= h: xx = 2 * h - xx if yy >= w: yy = 2 * w - yy yy = w - yy print(xx, yy, c0, c1) break