結果

問題 No.944 煎っぞ!
ユーザー tentententen
提出日時 2022-10-06 09:36:56
言語 Java21
(openjdk 21)
結果
AC  
実行時間 235 ms / 3,000 ms
コード長 1,726 bytes
コンパイル時間 2,676 ms
コンパイル使用メモリ 74,788 KB
実行使用メモリ 62,740 KB
最終ジャッジ日時 2023-08-30 21:26:56
合計ジャッジ時間 10,158 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 217 ms
60,416 KB
testcase_01 AC 216 ms
60,220 KB
testcase_02 AC 215 ms
60,564 KB
testcase_03 AC 216 ms
60,604 KB
testcase_04 AC 209 ms
60,172 KB
testcase_05 AC 214 ms
60,252 KB
testcase_06 AC 216 ms
60,448 KB
testcase_07 AC 214 ms
60,480 KB
testcase_08 AC 216 ms
60,444 KB
testcase_09 AC 212 ms
60,388 KB
testcase_10 AC 55 ms
50,368 KB
testcase_11 AC 102 ms
53,824 KB
testcase_12 AC 99 ms
51,944 KB
testcase_13 AC 44 ms
49,280 KB
testcase_14 AC 101 ms
53,788 KB
testcase_15 AC 96 ms
51,944 KB
testcase_16 AC 44 ms
49,120 KB
testcase_17 AC 43 ms
49,444 KB
testcase_18 AC 101 ms
54,032 KB
testcase_19 AC 105 ms
53,648 KB
testcase_20 AC 213 ms
60,020 KB
testcase_21 AC 222 ms
60,168 KB
testcase_22 AC 212 ms
60,228 KB
testcase_23 AC 211 ms
60,348 KB
testcase_24 AC 213 ms
60,412 KB
testcase_25 AC 209 ms
60,516 KB
testcase_26 AC 204 ms
60,368 KB
testcase_27 AC 203 ms
58,120 KB
testcase_28 AC 44 ms
49,400 KB
testcase_29 AC 46 ms
49,232 KB
testcase_30 AC 235 ms
60,460 KB
testcase_31 AC 230 ms
62,740 KB
testcase_32 AC 207 ms
60,392 KB
testcase_33 AC 218 ms
60,440 KB
testcase_34 AC 224 ms
60,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int sum = 0;
        HashSet<Integer> all = new HashSet<>();
        for (int i = 0; i < n; i++) {
            sum += sc.nextInt();
            all.add(sum);
        }
        int ans = 1;
        for (int i = 1; i <= Math.sqrt(sum); i++) {
            if (sum % i == 0) {
                if (check(i, all, sum)) {
                    ans = Math.max(ans, sum / i);
                }
                if (check(sum / i, all ,sum)) {
                    ans = Math.max(ans, i);
                }
            }
        }
        System.out.println(ans);
    }
    
    static boolean check(int x, HashSet<Integer> all, int sum) {
        for (int i = 1; i * x <= sum; i++) {
            if (!all.contains(i * x)) {
                return false;
            }
        }
        return true;
    }
}
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 String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0