結果
| 問題 |
No.751 Frac #2
|
| コンテスト | |
| ユーザー |
htensai
|
| 提出日時 | 2020-05-08 08:47:47 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,789 bytes |
| コンパイル時間 | 2,317 ms |
| コンパイル使用メモリ | 80,896 KB |
| 実行使用メモリ | 56,972 KB |
| 最終ジャッジ日時 | 2024-07-03 09:45:19 |
| 合計ジャッジ時間 | 9,781 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 19 WA * 17 |
ソースコード
import java.util.*;
public class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int n1 = sc.nextInt();
ArrayDeque<Integer> mothers = new ArrayDeque<>();
ArrayDeque<Integer> children = new ArrayDeque<>();
int x = sc.nextInt();
boolean isMPlus = true;
boolean isCPlus = true;
if (x < 0) {
isCPlus ^= true;
x *= -1;
}
children.add(x);
for (int i = 1; i < n1; i++) {
int y = sc.nextInt();
if (y < 0) {
isMPlus ^= true;
y *= -1;
}
mothers.add(y);
}
int n2 = sc.nextInt();
for (int i = 0; i < n2; i++) {
int y = sc.nextInt();
if (i % 2 == 0) {
if (y < 0) {
isMPlus ^= true;
y *= -1;
}
mothers.add(y);
} else {
if (y < 0) {
isCPlus ^= true;
y *= -1;
}
children.add(y);
}
}
long mother = 1;
long child = 1;
ArrayDeque<Integer> next = new ArrayDeque<>();
while (mothers.size() > 0) {
int m = mothers.poll();
while (children.size() > 0) {
int c = children.poll();
int gcd = getGCD(m, c);
m /= gcd;
c /= gcd;
if (c != 1) {
next.add(c);
}
if (m == 1) {
next.add(c);
break;
}
}
if (m != 1) {
mother *= m;
}
children.addAll(next);
next.clear();
}
while (children.size() > 0) {
child *= children.poll();
}
if (isMPlus ^ isCPlus) {
child *= -1;
}
System.out.println(child + " " + mother);
}
static int getGCD(int x, int y) {
if (x % y == 0) {
return y;
} else {
return getGCD(y, x % y);
}
}
}
htensai