結果
問題 | No.1738 What's in the box? |
ユーザー | tenten |
提出日時 | 2023-02-22 14:29:32 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 59 ms / 2,000 ms |
コード長 | 2,275 bytes |
コンパイル時間 | 2,324 ms |
コンパイル使用メモリ | 91,160 KB |
実行使用メモリ | 38,000 KB |
最終ジャッジ日時 | 2024-07-22 16:34:14 |
合計ジャッジ時間 | 7,860 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
37,084 KB |
testcase_01 | AC | 46 ms
37,108 KB |
testcase_02 | AC | 46 ms
37,004 KB |
testcase_03 | AC | 52 ms
37,076 KB |
testcase_04 | AC | 51 ms
37,332 KB |
testcase_05 | AC | 51 ms
36,976 KB |
testcase_06 | AC | 50 ms
37,316 KB |
testcase_07 | AC | 52 ms
37,304 KB |
testcase_08 | AC | 51 ms
37,476 KB |
testcase_09 | AC | 59 ms
38,000 KB |
testcase_10 | AC | 56 ms
36,968 KB |
testcase_11 | AC | 50 ms
37,276 KB |
testcase_12 | AC | 51 ms
37,348 KB |
testcase_13 | AC | 51 ms
36,780 KB |
testcase_14 | AC | 47 ms
36,980 KB |
testcase_15 | AC | 43 ms
37,160 KB |
testcase_16 | AC | 44 ms
36,800 KB |
testcase_17 | AC | 49 ms
36,972 KB |
testcase_18 | AC | 50 ms
37,108 KB |
testcase_19 | AC | 49 ms
37,192 KB |
testcase_20 | AC | 49 ms
36,964 KB |
testcase_21 | AC | 48 ms
37,008 KB |
testcase_22 | AC | 45 ms
37,076 KB |
testcase_23 | AC | 46 ms
37,128 KB |
testcase_24 | AC | 45 ms
37,196 KB |
testcase_25 | AC | 46 ms
36,832 KB |
testcase_26 | AC | 44 ms
37,204 KB |
testcase_27 | AC | 46 ms
37,248 KB |
testcase_28 | AC | 46 ms
37,228 KB |
testcase_29 | AC | 46 ms
37,180 KB |
testcase_30 | AC | 44 ms
37,016 KB |
testcase_31 | AC | 45 ms
37,132 KB |
testcase_32 | AC | 45 ms
36,948 KB |
testcase_33 | AC | 47 ms
37,400 KB |
testcase_34 | AC | 50 ms
37,136 KB |
testcase_35 | AC | 48 ms
37,256 KB |
testcase_36 | AC | 49 ms
37,256 KB |
testcase_37 | AC | 49 ms
37,124 KB |
testcase_38 | AC | 50 ms
37,008 KB |
testcase_39 | AC | 52 ms
36,964 KB |
testcase_40 | AC | 52 ms
37,296 KB |
testcase_41 | AC | 51 ms
36,964 KB |
testcase_42 | AC | 49 ms
37,264 KB |
testcase_43 | AC | 52 ms
37,208 KB |
testcase_44 | AC | 52 ms
36,784 KB |
testcase_45 | AC | 51 ms
37,080 KB |
testcase_46 | AC | 53 ms
37,388 KB |
testcase_47 | AC | 49 ms
37,196 KB |
testcase_48 | AC | 51 ms
37,300 KB |
testcase_49 | AC | 49 ms
36,964 KB |
testcase_50 | AC | 49 ms
37,184 KB |
testcase_51 | AC | 50 ms
37,304 KB |
testcase_52 | AC | 56 ms
37,228 KB |
testcase_53 | AC | 47 ms
36,972 KB |
testcase_54 | AC | 48 ms
37,204 KB |
testcase_55 | AC | 47 ms
36,960 KB |
testcase_56 | AC | 45 ms
37,136 KB |
testcase_57 | AC | 45 ms
37,200 KB |
testcase_58 | AC | 46 ms
37,076 KB |
testcase_59 | AC | 46 ms
37,040 KB |
testcase_60 | AC | 47 ms
37,084 KB |
testcase_61 | AC | 45 ms
37,268 KB |
testcase_62 | AC | 46 ms
37,244 KB |
testcase_63 | AC | 44 ms
37,120 KB |
testcase_64 | AC | 45 ms
36,844 KB |
testcase_65 | AC | 48 ms
36,972 KB |
testcase_66 | AC | 47 ms
36,804 KB |
testcase_67 | AC | 44 ms
37,128 KB |
testcase_68 | AC | 46 ms
36,980 KB |
testcase_69 | AC | 44 ms
36,988 KB |
testcase_70 | AC | 43 ms
36,780 KB |
testcase_71 | AC | 45 ms
37,192 KB |
testcase_72 | AC | 43 ms
37,248 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); long[] values = new long[n]; long total = 0; for (int i = 0; i < n; i++) { values[i] = sc.nextInt(); total += values[i]; } long gcd = getGCD(m, total); if (gcd > 0) { m /= gcd; total /= gcd; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { if (i > 0) { sb.append(" "); } if (total == 0) { sb.append(0); } else { sb.append(values[i] * m / total); } } System.out.println(sb); } static long getGCD(long x, long y) { if (y == 0) { return x; } else { return getGCD(y, x % y); } } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }