結果

問題 No.61 リベリオン
コンテスト
ユーザー GOTKAKO
提出日時 2025-06-29 18:52:34
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,800 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,701 ms
コンパイル使用メモリ 519,968 KB
最終ジャッジ日時 2026-07-12 23:20:58
合計ジャッジ時間 3,607 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/x86_64-pc-linux-gnu/bits/stdc++.h:60,
                 from main.cpp:1:
/home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/numeric: In instantiation of 'constexpr std::common_type_t<_Mn, _Nn> std::gcd(_Mn, _Nn) [with _Mn = __int128; _Nn = __int128; common_type_t<_Mn, _Nn> = __int128]':
main.cpp:37:35:   required from here
   37 |             __int128_t x,y,g = gcd(A,-B);
      |                                ~~~^~~~~~
/home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/numeric:181:21: error: static assertion failed: std::gcd arguments must be integers
  181 |       static_assert(is_integral_v<_Mn> && is_integral_v<_Nn>,
      |                     ^~~~~~~~~~~~~~~~~~
/home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/numeric:181:21: note: 'std::is_integral_v<__int128>' evaluates to false
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/bits/cpp_type_traits.h:42,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/bits/stl_algobase.h:61,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/algorithm:62,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/x86_64-pc-linux-gnu/bits/stdc++.h:53:
/home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/type_traits: In instantiation of 'struct std::make_unsigned<__int128>':
/home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/type_traits:2144:11:   required by substitution of 'template<class _Tp> using std::make_unsigned_t = typename std::make_unsigned::type [with _Tp = __int128]'
 2144 |     using make_unsigned_t = typename make_unsigned<_Tp>::type;
      |           ^~~~~~~~~~~~~~~
/home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/numeric:188:24:   required from 'constexpr std::common_type_t<_Mn, _Nn> std::gcd(_Mn, _Nn) [with _Mn = __int128; _

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using bigint = boost::multiprecision::cpp_int;

__int128_t extgcd(__int128_t a, __int128_t b, __int128_t &x,__int128_t &y){
    if(b == 0){x = 1,y = 0; return a;}
    __int128_t g = extgcd(b,a%b,y,x);
    y -= a/b*x; return g;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int Q; cin >> Q;
    while(Q--){
        long long W,H,D,Mx,My,Hx,Hy,Vx,Vy;
        cin >> W >> H >> D >> Mx >> My >> Hx >> Hy >> Vx >> Vy;
        if(Vx < 0) Vx = -Vx,Mx = W-Mx,Hx = W-Hx;
        if(Vy < 0) Vy = -Vy,My = H-My,Hy = H-Hy;

        if(Vx == 0){
            if(Mx == Hx && ((My > Hy && (My-Hy) <= D*Vy) || (My < Hy && (2*H-My-Hy) <= D*Vy))) cout << "Hit\n";
            else cout << "Miss\n";
            continue;
        }
        if(Vy == 0){
            if(My == Hy && ((Mx > Hx && (Mx-Hx) <= D*Vx) || (Mx < Hx && (2*W-Mx-Hx) <= D*Vx))) cout << "Hit\n";
            else cout << "Miss\n";
            continue;
        }
        auto solve = [&](long long Gx,long long Gy) -> bool {
            __int128_t A = 2*W*Vy,B = -2*H*Vx,C = (Gy-Hy)*Vx-(Gx-Hx)*Vy;
            __int128_t x,y,g = gcd(A,-B);
            if(C%g != 0) return false;
            A /= g,B /= g,C /= g;
            extgcd(A,B,x,y);
            bigint m = C*y%A;
            //assert((m*H*2+Gy-Hy)%Vy == 0);
            bigint t = (m*H*2+Gy-Hy)/Vy;
            
            t %= A*2*H/Vy;
            if(t < 0) t += A*2*H/Vy;
            return t<=D;
        };
        long long g = gcd(Vx,Vy);
        D *= g; Vx /= g,Vy /= g;
        if(solve(Mx,My)||solve(Mx,2*H-My)||solve(2*W-Mx,My)||solve(2*W-Mx,2*H-My)) cout << "Hit\n";
        else cout << "Miss\n";
    }
}
0