結果

問題 No.1486 ロボット
ユーザー bluemeganebluemegane
提出日時 2021-04-23 23:00:56
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 1,351 bytes
コンパイル時間 4,332 ms
コンパイル使用メモリ 107,976 KB
実行使用メモリ 27,904 KB
最終ジャッジ日時 2024-07-04 08:38:18
合計ジャッジ時間 2,631 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;

public class Hello
{
    public static int a, b, c, d, e;
    static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        a = int.Parse(line[0]);
        b = int.Parse(line[1]);
        c = int.Parse(line[2]);
        d = int.Parse(line[3]);
        e = int.Parse(line[4]);
        getAns();
    }
    static void putA (bool[] s, int x, int y)
    {
        var sL = s.Length;
        var p = 0;
        while (p < sL)
        {
            for (int i = 0; i < x; i++) s[p++] = true;
            p += y;
        }
    }
    static void getAns ()
    {
        var gcd = Gcd(a+b, c+d);
        var lcm = (a + b) * (c + d) / gcd;
        var t0 = e % lcm;
        var t1 = e / lcm;
        var s0 = new bool[lcm];
        var s1 = new bool[lcm];
        putA(s0, a, b);
        putA(s1, c, d);
        var count = 0;
        for (int i = 0; i < t0; i++)
        {
            if (s0[i] && s1[i]) count++;
        }
        var countb = 0;
        for (int i = 0; i < lcm; i++)
        {
            if (s0[i] && s1[i]) countb++;
        }
        Console.WriteLine(countb * t1 + count);
    }
    static int Gcd(int a, int b)
    {
        if (a < b) return Gcd(b, a);
        while (b != 0)
        {
            var w = a % b;
            a = b;
            b = w;
        }
        return a;
    }
}
0