結果

問題 No.61 リベリオン
ユーザー woodsgreenwoodsgreen
提出日時 2022-01-11 21:02:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 5,000 ms
コード長 941 bytes
コンパイル時間 2,119 ms
コンパイル使用メモリ 193,876 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 21:12:02
合計ジャッジ時間 2,846 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 44 ms
5,376 KB
testcase_04 AC 47 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int q;
int w,h,d,hx,hy,mx,my,vx,vy,g;
int gcd(int a,int b){
    if(a<0) a=-a;
    if(b<0) b=-b;
    int r;
    while(a){
        r=b; b=a; a=r%a;
    }
    return b;
}
int main(){
    scanf("%d",&q);
    for(int i=0;i<q;++i){
        scanf("%d%d%d%d%d%d%d%d%d",&w,&h,&d,&mx,&my,&hx,&hy,&vx,&vy);
        g=gcd(vx,vy);
        vx/=g; vy/=g;
        d=min(1100ll,(long long)d*g);
        for(int j=0;j<d&&(hx!=mx||hy!=my);++j){
            hx+=vx;
            hy+=vy;
            while(true){
                if(hx<0){ hx=0-hx; vx=-vx; continue; }
                if(hx>w){ hx=2*w-hx; vx=-vx; continue; }
                if(hy<0){ hy=0-hy; vy=-vy; continue; }
                if(hy>h){ hy=2*h-hy; vy=-vy; continue; }
                break;
            }
        }
        if(hx==mx&&hy==my) printf("Hit\n");
        else printf("Miss\n");
    }
    return 0;
}
0