結果
問題 |
No.1486 ロボット
|
ユーザー |
![]() |
提出日時 | 2021-04-29 11:57:40 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 77 ms / 2,000 ms |
コード長 | 1,787 bytes |
コンパイル時間 | 1,932 ms |
コンパイル使用メモリ | 77,788 KB |
実行使用メモリ | 42,228 KB |
最終ジャッジ日時 | 2024-07-08 10:52:09 |
合計ジャッジ時間 | 4,116 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
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(); } }