結果
問題 | No.62 リベリオン(Extra) |
ユーザー | maine_honzuki |
提出日時 | 2020-05-10 01:42:34 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,070 bytes |
コンパイル時間 | 1,325 ms |
コンパイル使用メモリ | 172,340 KB |
実行使用メモリ | 6,940 KB |
最終ジャッジ日時 | 2024-07-06 12:07:49 |
合計ジャッジ時間 | 6,349 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 3 ms
6,940 KB |
testcase_02 | AC | 1,268 ms
6,940 KB |
testcase_03 | AC | 1,237 ms
6,940 KB |
testcase_04 | WA | - |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; ll W, H, D, Vx, Vy; ll gcd(ll a, ll b) { while (b) { ll c = b; b = a % b; a = c; } return a; } ll extgcd(ll a, ll b, ll& x, ll& y) { if (b) { ll d = extgcd(b, a % b, y, x); y -= a / b * x; return d; } else { x = 1; y = 0; return a; } } ll rem(ll& a, ll b) { return ((a %= b) += b) %= b; } bool hit(ll Mx, ll My) { ll My_origin = My; ll w = 2 * W, h = 2 * H; cerr << Mx << " " << My << endl; ll a, b; ll g = extgcd(Vx, 2 * W, a, b); cerr << "g:" << g << endl; if (Mx % g) return false; rem(a, w); a *= Mx / g; rem(a, w / g); cerr << "a:" << a << endl; ll can_add_to_a = w / g; cerr << "can_add_to_a:" << can_add_to_a << endl; My -= Vy * (a % (h)); rem(My, h); cerr << "My:" << My << endl; if (My == 0) { return a <= D; } ll c, d; g = extgcd(Vy * can_add_to_a, h, c, d); assert(Vy * can_add_to_a * c + h * d == g); c *= can_add_to_a; if (My % g) return false; c *= (My / g); cerr << "Mx,My:" << endl << Mx << " " << My_origin << endl; cerr << (Vx * ((a + c) % w)) % w << " " << (Vy * ((a + c) % h)) % h << endl; cerr << (Vx * a) % w << " " << (Vy * a) % w << endl; rem(c, h / gcd(h, Vy) * can_add_to_a); cerr << "c:" << c << endl; cerr << "h:" << h << endl; cerr << h % gcd(h, Vy) << endl; cerr << h / gcd(h, Vy) << endl; cerr << "Mx,My:" << endl << Mx << " " << My_origin << endl; cerr << (Vx * ((a + c) % w)) % w << " " << (Vy * ((a + c) % h)) % h << endl; cerr << (Vx * a) % w << " " << (Vy * a) % w << endl; cerr << c % can_add_to_a << endl; /* while (c < a) c += 2 * H / g; */ return c + a <= D; } int main() { int Q; cin >> Q; while (Q--) { ll Mx, My, Hx, Hy; cin >> W >> H >> D >> Mx >> My >> Hx >> Hy >> Vx >> Vy; ll g = gcd(abs(Vx), abs(Vy)); Vx /= g; Vy /= g; D *= g; if (Vx < 0) { Vx *= -1; Hx = W - Hx; Mx = W - Mx; } if (Vy < 0) { Vy *= -1; Hy = H - Hy; My = H - My; } Vx %= 2 * W; Vy %= 2 * H; ll mx, my; bool ans = false; cerr << Vx << " " << Vy << endl; for (int i = 0; i < 4; i++) { if (i < 2) mx = Mx; else mx = W * 2 - Mx; if (i % 2 == 0) my = My; else my = H * 2 - My; mx -= Hx; my -= Hy; if (mx < 0) mx += W * 2; if (my < 0) my += H * 2; bool flag = hit(mx, my); ans |= flag; cerr << i << " " << (flag ? "Yes" : "No") << endl; cerr << endl; } cout << (ans ? "Hit" : "Miss") << endl; } }