結果

問題 No.61 リベリオン
ユーザー nanophoto12nanophoto12
提出日時 2014-11-15 23:53:17
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 220 ms / 5,000 ms
コード長 2,048 bytes
コンパイル時間 3,797 ms
コンパイル使用メモリ 105,984 KB
実行使用メモリ 23,508 KB
最終ジャッジ日時 2024-04-21 17:18:52
合計ジャッジ時間 3,824 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
18,816 KB
testcase_01 AC 29 ms
19,200 KB
testcase_02 AC 29 ms
19,072 KB
testcase_03 AC 220 ms
23,508 KB
testcase_04 AC 218 ms
23,376 KB
testcase_05 AC 29 ms
19,328 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    public static void Main(string[] args)
    {
        var q = int.Parse(Console.ReadLine());
        List<string> results = new List<string>();
        for (int i = 0; i < q; i++)
        {
            results.Add(Solve());    
        }
        foreach (var element in results)
        {
            Console.WriteLine(element);
        }
    }

    private static int Gcd(int a, int b)
    {
        if (b == 0)
        {
            return a;
        }
        return Gcd(b, a % b);
    }

    private static string Solve()
    {
        var line = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var w = line[0];
        var h = line[1];
        var d = line[2];
        var mx = line[3];
        var my = line[4];
        var hx = line[5];
        var hy = line[6];
        var vx = line[7];
        var vy = line[8];
        var hit = new bool[w+1,h+1];

        var g = CalculateGcd(vx, vy);
        vx /= g;
        vy /= g;
        d *= g;

        for (int i = 0; i < Math.Min(d + 1, 1025); i++)
        {
            var dx = hx + vx*i;
            var dy = hy + vy*i;
            dx %= (2 * w);
            dy %= (2 * h);
            dx = Math.Abs(dx);
            dy = Math.Abs(dy);
            if (dx >= w)
            {
                dx = 2 * w - dx;
            }
            if (dy >= h)
            {
                dy= 2 * h - dy;
            }
            hit[dx, dy] = true;
        }
        if (hit[mx, my])
        {
            return "Hit";            
        }
        return "Miss";
    }

    private static int CalculateGcd(int vx, int vy)
    {
        int g = 0;
        if (vx == 0)
        {
            g = Math.Abs(vy);
        }
        else if (vy == 0)
        {
            g = Math.Abs(vx);
        }
        else
        {
            g = Gcd(Math.Abs(vx), Math.Abs(vy));
        }
        return g;
    }
}
0