結果

問題 No.944 煎っぞ!
ユーザー htensaihtensai
提出日時 2019-12-09 11:21:51
言語 Java21
(openjdk 21)
結果
AC  
実行時間 520 ms / 3,000 ms
コード長 1,608 bytes
コンパイル時間 3,646 ms
コンパイル使用メモリ 78,516 KB
実行使用メモリ 60,980 KB
最終ジャッジ日時 2023-09-03 16:30:49
合計ジャッジ時間 21,110 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 512 ms
60,472 KB
testcase_01 AC 494 ms
60,400 KB
testcase_02 AC 496 ms
60,620 KB
testcase_03 AC 499 ms
60,844 KB
testcase_04 AC 470 ms
60,704 KB
testcase_05 AC 486 ms
60,604 KB
testcase_06 AC 508 ms
60,748 KB
testcase_07 AC 490 ms
60,364 KB
testcase_08 AC 492 ms
60,980 KB
testcase_09 AC 497 ms
60,852 KB
testcase_10 AC 191 ms
56,676 KB
testcase_11 AC 283 ms
60,204 KB
testcase_12 AC 252 ms
59,648 KB
testcase_13 AC 136 ms
56,276 KB
testcase_14 AC 305 ms
60,612 KB
testcase_15 AC 244 ms
59,560 KB
testcase_16 AC 133 ms
55,980 KB
testcase_17 AC 137 ms
55,952 KB
testcase_18 AC 286 ms
60,412 KB
testcase_19 AC 282 ms
60,348 KB
testcase_20 AC 475 ms
60,604 KB
testcase_21 AC 520 ms
60,324 KB
testcase_22 AC 458 ms
60,376 KB
testcase_23 AC 480 ms
60,276 KB
testcase_24 AC 478 ms
58,560 KB
testcase_25 AC 498 ms
60,364 KB
testcase_26 AC 490 ms
60,364 KB
testcase_27 AC 510 ms
60,444 KB
testcase_28 AC 127 ms
55,796 KB
testcase_29 AC 128 ms
56,196 KB
testcase_30 AC 493 ms
60,556 KB
testcase_31 AC 471 ms
60,264 KB
testcase_32 AC 463 ms
60,500 KB
testcase_33 AC 504 ms
60,924 KB
testcase_34 AC 494 ms
60,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        int total = 0;
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
            total += arr[i];
        }
        TreeSet<Integer> set = new TreeSet<>();
        for (int i = 1; i <= Math.sqrt(total); i++) {
            if (total % i == 0) {
                set.add(total / i);
                int idx = 0;
                boolean flag = true;
                int cur = 0;
                while (idx < n) {
                    cur += arr[idx];
                    if (cur > i) {
                        flag = false;
                        break;
                    } else if (cur == i) {
                        cur = 0;
                    }
                    idx++;
                }
                if (flag) {
                    System.out.println(total / i);
                    return;
                }
            }
        }
        for (int x : set) {
            int idx = 0;
            boolean flag = true;
            int cur = 0;
            while (idx < n) {
                cur += arr[idx];
                if (cur > x) {
                    flag = false;
                    break;
                } else if (cur == x) {
                    cur = 0;
                }
                idx++;
            }
            if (flag) {
                System.out.println(total / x);
                return;
            }
        }
        System.out.println(1);
    }
}
0