結果

問題 No.1330 Multiply or Divide
ユーザー tentententen
提出日時 2023-02-02 09:47:28
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,384 bytes
コンパイル時間 3,482 ms
コンパイル使用メモリ 85,684 KB
実行使用メモリ 62,752 KB
最終ジャッジ日時 2023-09-14 17:10:00
合計ジャッジ時間 16,129 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 246 ms
58,296 KB
testcase_02 AC 46 ms
49,520 KB
testcase_03 AC 46 ms
49,408 KB
testcase_04 AC 46 ms
49,560 KB
testcase_05 AC 46 ms
49,332 KB
testcase_06 AC 204 ms
56,336 KB
testcase_07 WA -
testcase_08 AC 343 ms
61,188 KB
testcase_09 AC 339 ms
61,448 KB
testcase_10 AC 335 ms
61,132 KB
testcase_11 AC 344 ms
60,932 KB
testcase_12 AC 341 ms
61,260 KB
testcase_13 AC 48 ms
49,348 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 47 ms
49,384 KB
testcase_17 WA -
testcase_18 AC 340 ms
61,800 KB
testcase_19 AC 337 ms
61,208 KB
testcase_20 AC 337 ms
61,520 KB
testcase_21 AC 337 ms
61,648 KB
testcase_22 AC 336 ms
61,524 KB
testcase_23 AC 268 ms
62,752 KB
testcase_24 AC 45 ms
47,516 KB
testcase_25 AC 45 ms
49,688 KB
testcase_26 AC 45 ms
49,336 KB
testcase_27 AC 47 ms
49,472 KB
testcase_28 AC 45 ms
47,412 KB
testcase_29 AC 46 ms
49,320 KB
testcase_30 AC 46 ms
49,412 KB
testcase_31 AC 45 ms
49,408 KB
testcase_32 AC 47 ms
49,436 KB
testcase_33 AC 47 ms
49,676 KB
testcase_34 AC 294 ms
59,128 KB
testcase_35 AC 177 ms
55,708 KB
testcase_36 AC 276 ms
58,672 KB
testcase_37 AC 273 ms
58,276 KB
testcase_38 AC 218 ms
56,112 KB
testcase_39 AC 212 ms
56,128 KB
testcase_40 AC 192 ms
55,976 KB
testcase_41 AC 157 ms
55,548 KB
testcase_42 AC 265 ms
58,732 KB
testcase_43 AC 276 ms
58,416 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];
        int currentMax = 0;
        for (int i = n - 1; i >= 0; i--) {
            if (values[i] % p > 0) {
                currentMax = values[i];
                break;
            }
        }
        if (currentMax == 0) {
            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