結果

問題 No.1486 ロボット
ユーザー tentententen
提出日時 2021-04-29 11:57:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 1,787 bytes
コンパイル時間 2,516 ms
コンパイル使用メモリ 74,160 KB
実行使用メモリ 55,744 KB
最終ジャッジ日時 2023-09-22 20:09:44
合計ジャッジ時間 3,968 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,304 KB
testcase_01 AC 42 ms
49,832 KB
testcase_02 AC 43 ms
49,648 KB
testcase_03 AC 42 ms
49,528 KB
testcase_04 AC 43 ms
49,396 KB
testcase_05 AC 43 ms
49,608 KB
testcase_06 AC 61 ms
55,744 KB
testcase_07 AC 62 ms
55,580 KB
testcase_08 AC 60 ms
53,640 KB
testcase_09 AC 43 ms
49,416 KB
testcase_10 AC 46 ms
49,464 KB
testcase_11 AC 45 ms
49,660 KB
testcase_12 AC 42 ms
49,392 KB
testcase_13 AC 43 ms
49,292 KB
testcase_14 AC 58 ms
51,476 KB
testcase_15 AC 46 ms
50,324 KB
testcase_16 AC 49 ms
50,588 KB
testcase_17 AC 49 ms
50,200 KB
testcase_18 AC 47 ms
50,168 KB
testcase_19 AC 44 ms
49,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int e = sc.nextInt();
        int ab = a + b;
        int cd = c + d;
        int lcm = getLCM(ab, cd);
        int[] imos = new int[lcm];
        for (int i = 0; i * ab < lcm; i++) {
            imos[i * ab]++;
            imos[i * ab + a]--;
        }
        for (int i = 0; i * cd < lcm; i++) {
            imos[i * cd]++;
            imos[i * cd + c]--;
        }
        int base = 1;
        for (int i = 1; i < lcm; i++) {
            imos[i] += imos[i - 1];
            base += imos[i] / 2;
        }
        int ans = base * (e / lcm);
        for (int i = 0; i < e % lcm; i++) {
            ans += imos[i] / 2;
        }
        System.out.println(ans);
    }
    
    static int getLCM(int x, int y) {
        return x / getGCD(x, y) * y;
    }
    
    static int getGCD(int x, int y) {
        if (x % y == 0) {
            return y;
        } else {
            return getGCD(y, x % y);
        }
    }
}

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0