結果

問題 No.1330 Multiply or Divide
ユーザー tentententen
提出日時 2023-02-02 10:47:54
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,394 bytes
コンパイル時間 2,615 ms
コンパイル使用メモリ 87,168 KB
実行使用メモリ 59,116 KB
最終ジャッジ日時 2023-09-14 17:53:04
合計ジャッジ時間 13,978 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 247 ms
43,888 KB
testcase_02 AC 41 ms
34,120 KB
testcase_03 AC 40 ms
33,500 KB
testcase_04 AC 39 ms
33,488 KB
testcase_05 AC 40 ms
33,452 KB
testcase_06 AC 210 ms
42,628 KB
testcase_07 WA -
testcase_08 AC 399 ms
48,212 KB
testcase_09 AC 413 ms
47,412 KB
testcase_10 AC 399 ms
48,756 KB
testcase_11 AC 380 ms
48,324 KB
testcase_12 AC 403 ms
48,068 KB
testcase_13 AC 41 ms
33,520 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 41 ms
33,520 KB
testcase_17 WA -
testcase_18 AC 332 ms
47,656 KB
testcase_19 AC 327 ms
48,680 KB
testcase_20 AC 325 ms
48,420 KB
testcase_21 AC 332 ms
48,140 KB
testcase_22 AC 338 ms
48,732 KB
testcase_23 AC 272 ms
49,780 KB
testcase_24 AC 41 ms
33,440 KB
testcase_25 AC 45 ms
33,488 KB
testcase_26 AC 46 ms
33,568 KB
testcase_27 AC 40 ms
33,672 KB
testcase_28 AC 40 ms
33,524 KB
testcase_29 AC 40 ms
33,472 KB
testcase_30 AC 39 ms
33,668 KB
testcase_31 AC 40 ms
33,804 KB
testcase_32 AC 39 ms
33,480 KB
testcase_33 AC 40 ms
33,524 KB
testcase_34 AC 289 ms
45,428 KB
testcase_35 AC 194 ms
41,224 KB
testcase_36 AC 289 ms
44,628 KB
testcase_37 AC 272 ms
44,548 KB
testcase_38 AC 220 ms
42,312 KB
testcase_39 AC 207 ms
41,580 KB
testcase_40 AC 194 ms
41,576 KB
testcase_41 AC 166 ms
40,516 KB
testcase_42 AC 262 ms
44,460 KB
testcase_43 AC 273 ms
44,092 KB
testcase_44 WA -
testcase_45 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
        int p = sc.nextInt();
        int[] values = new int[n];
        for (int i = 0; i < n; i++) {
            values[i] = sc.nextInt();
        }
        Arrays.sort(values);
        if (values[n - 1] > m) {
            System.out.println(1);
            return;
        }
        int realMax = values[n - 1];
        for (int i = 0; i < n; i++) {
            while (values[i] % p == 0) {
                values[i] /= p;
            }
        }
        Arrays.sort(values);
        int currentMax = values[n - 1];
        if (currentMax <= 1 ) {
            System.out.println(-1);
            return;
        }
        int ans = 0;
        long base = 1;
        while (base <= m) {
            if (base * realMax > m) {
                base *= realMax;
                ans++;
            } else {
                base *= currentMax;
                ans++;
            }
        }
        System.out.println(ans);
    }
}
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();
    }
    
}
0