結果

問題 No.944 煎っぞ!
ユーザー tentententen
提出日時 2022-08-04 09:51:07
言語 Java21
(openjdk 21)
結果
AC  
実行時間 240 ms / 3,000 ms
コード長 1,697 bytes
コンパイル時間 2,220 ms
コンパイル使用メモリ 76,240 KB
実行使用メモリ 62,688 KB
最終ジャッジ日時 2023-10-12 06:38:41
合計ジャッジ時間 9,625 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 210 ms
60,432 KB
testcase_01 AC 214 ms
60,428 KB
testcase_02 AC 214 ms
60,340 KB
testcase_03 AC 214 ms
60,888 KB
testcase_04 AC 210 ms
60,776 KB
testcase_05 AC 208 ms
60,632 KB
testcase_06 AC 211 ms
60,652 KB
testcase_07 AC 211 ms
60,492 KB
testcase_08 AC 212 ms
60,476 KB
testcase_09 AC 209 ms
60,452 KB
testcase_10 AC 53 ms
50,260 KB
testcase_11 AC 112 ms
54,132 KB
testcase_12 AC 96 ms
51,500 KB
testcase_13 AC 43 ms
49,420 KB
testcase_14 AC 101 ms
54,064 KB
testcase_15 AC 98 ms
52,264 KB
testcase_16 AC 43 ms
49,196 KB
testcase_17 AC 43 ms
49,288 KB
testcase_18 AC 100 ms
54,060 KB
testcase_19 AC 110 ms
54,416 KB
testcase_20 AC 213 ms
60,656 KB
testcase_21 AC 221 ms
60,292 KB
testcase_22 AC 211 ms
61,108 KB
testcase_23 AC 210 ms
60,680 KB
testcase_24 AC 208 ms
60,960 KB
testcase_25 AC 204 ms
60,464 KB
testcase_26 AC 209 ms
60,636 KB
testcase_27 AC 196 ms
58,244 KB
testcase_28 AC 42 ms
49,344 KB
testcase_29 AC 42 ms
49,272 KB
testcase_30 AC 222 ms
60,576 KB
testcase_31 AC 240 ms
62,688 KB
testcase_32 AC 217 ms
60,656 KB
testcase_33 AC 221 ms
61,092 KB
testcase_34 AC 227 ms
60,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static HashSet<Integer> sums = new HashSet<>();
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int total = 0;
        while (n-- > 0) {
            total += sc.nextInt();
            sums.add(total);
        }
        int ans = 1;
        for (int i = 1; i <= Math.sqrt(total); i++) {
            if (total % i == 0) {
                if (check(i, total)) {
                    ans = Math.max(i, ans);
                }
                if (check(total / i, total)) {
                    ans = Math.max(total / i, ans);
                }
            }
        }
        System.out.println(ans);
    }
    
    static boolean check(int count, int total) {
        int num = total / count;
        for (int i = 1; i <= count; i++) {
            if (!sums.contains(i * num)) {
                return false;
            }
        }
        return true;
    }
}

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    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