結果
問題 | No.2968 Final MIGISITA Strike |
ユーザー | 👑 rin204 |
提出日時 | 2024-11-16 23:07:32 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 768 ms / 2,525 ms |
コード長 | 3,217 bytes |
コンパイル時間 | 336 ms |
コンパイル使用メモリ | 82,412 KB |
実行使用メモリ | 121,196 KB |
最終ジャッジ日時 | 2024-11-16 23:07:58 |
合計ジャッジ時間 | 22,648 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 34 ms
52,880 KB |
testcase_01 | AC | 35 ms
52,352 KB |
testcase_02 | AC | 34 ms
52,864 KB |
testcase_03 | AC | 35 ms
52,352 KB |
testcase_04 | AC | 35 ms
52,352 KB |
testcase_05 | AC | 36 ms
52,948 KB |
testcase_06 | AC | 35 ms
52,992 KB |
testcase_07 | AC | 35 ms
52,864 KB |
testcase_08 | AC | 37 ms
52,992 KB |
testcase_09 | AC | 36 ms
52,864 KB |
testcase_10 | AC | 392 ms
99,140 KB |
testcase_11 | AC | 400 ms
107,584 KB |
testcase_12 | AC | 214 ms
86,528 KB |
testcase_13 | AC | 304 ms
91,356 KB |
testcase_14 | AC | 203 ms
86,144 KB |
testcase_15 | AC | 671 ms
109,680 KB |
testcase_16 | AC | 569 ms
107,056 KB |
testcase_17 | AC | 518 ms
101,592 KB |
testcase_18 | AC | 399 ms
96,196 KB |
testcase_19 | AC | 480 ms
99,432 KB |
testcase_20 | AC | 549 ms
107,632 KB |
testcase_21 | AC | 293 ms
85,120 KB |
testcase_22 | AC | 332 ms
89,216 KB |
testcase_23 | AC | 689 ms
117,148 KB |
testcase_24 | AC | 685 ms
111,800 KB |
testcase_25 | AC | 768 ms
121,196 KB |
testcase_26 | AC | 329 ms
90,236 KB |
testcase_27 | AC | 445 ms
95,424 KB |
testcase_28 | AC | 339 ms
90,296 KB |
testcase_29 | AC | 413 ms
94,068 KB |
testcase_30 | AC | 145 ms
84,352 KB |
testcase_31 | AC | 141 ms
83,672 KB |
testcase_32 | AC | 153 ms
87,084 KB |
testcase_33 | AC | 140 ms
83,072 KB |
testcase_34 | AC | 324 ms
89,136 KB |
testcase_35 | AC | 302 ms
88,252 KB |
testcase_36 | AC | 166 ms
78,812 KB |
testcase_37 | AC | 274 ms
86,952 KB |
testcase_38 | AC | 283 ms
87,724 KB |
testcase_39 | AC | 285 ms
86,528 KB |
testcase_40 | AC | 394 ms
92,556 KB |
testcase_41 | AC | 275 ms
90,028 KB |
testcase_42 | AC | 254 ms
86,400 KB |
testcase_43 | AC | 311 ms
89,728 KB |
testcase_44 | AC | 421 ms
97,456 KB |
testcase_45 | AC | 215 ms
80,768 KB |
testcase_46 | AC | 491 ms
103,484 KB |
testcase_47 | AC | 359 ms
93,160 KB |
testcase_48 | AC | 402 ms
98,516 KB |
testcase_49 | AC | 61 ms
69,084 KB |
testcase_50 | AC | 241 ms
83,712 KB |
testcase_51 | AC | 327 ms
90,816 KB |
testcase_52 | AC | 317 ms
92,416 KB |
testcase_53 | AC | 403 ms
93,480 KB |
testcase_54 | AC | 204 ms
81,536 KB |
testcase_55 | AC | 524 ms
100,696 KB |
testcase_56 | AC | 287 ms
88,216 KB |
testcase_57 | AC | 458 ms
99,868 KB |
testcase_58 | AC | 391 ms
96,792 KB |
testcase_59 | AC | 288 ms
87,200 KB |
testcase_60 | AC | 244 ms
84,300 KB |
testcase_61 | AC | 224 ms
83,328 KB |
testcase_62 | AC | 395 ms
94,988 KB |
testcase_63 | AC | 387 ms
95,140 KB |
testcase_64 | AC | 36 ms
52,864 KB |
testcase_65 | AC | 174 ms
89,584 KB |
testcase_66 | AC | 188 ms
92,924 KB |
ソースコード
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) - 1) // 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 if diff + s <= 0: lef = bt rig = t while rig - lef > 1: mid = (rig + lef) // 2 diff = 0 diff -= (mid + X) // h * c diff -= (mid + 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 c0 %= MOD c1 %= MOD print(xx, yy, c0, c1) break bt = t 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 c0 %= MOD c1 %= MOD print(xx, yy, c0, c1) break