結果

問題 No.944 煎っぞ!
ユーザー tentententen
提出日時 2020-08-26 09:54:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 522 ms / 3,000 ms
コード長 1,531 bytes
コンパイル時間 3,571 ms
コンパイル使用メモリ 78,060 KB
実行使用メモリ 48,612 KB
最終ジャッジ日時 2024-04-24 15:59:54
合計ジャッジ時間 17,057 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 499 ms
48,120 KB
testcase_01 AC 473 ms
48,104 KB
testcase_02 AC 408 ms
47,060 KB
testcase_03 AC 476 ms
48,352 KB
testcase_04 AC 446 ms
48,144 KB
testcase_05 AC 507 ms
48,244 KB
testcase_06 AC 504 ms
48,276 KB
testcase_07 AC 522 ms
48,228 KB
testcase_08 AC 460 ms
48,520 KB
testcase_09 AC 473 ms
48,176 KB
testcase_10 AC 169 ms
42,052 KB
testcase_11 AC 267 ms
47,236 KB
testcase_12 AC 221 ms
46,692 KB
testcase_13 AC 108 ms
39,932 KB
testcase_14 AC 285 ms
47,552 KB
testcase_15 AC 214 ms
46,248 KB
testcase_16 AC 112 ms
40,952 KB
testcase_17 AC 116 ms
41,156 KB
testcase_18 AC 267 ms
47,588 KB
testcase_19 AC 264 ms
47,556 KB
testcase_20 AC 489 ms
48,416 KB
testcase_21 AC 492 ms
48,612 KB
testcase_22 AC 463 ms
48,352 KB
testcase_23 AC 483 ms
48,260 KB
testcase_24 AC 457 ms
48,220 KB
testcase_25 AC 521 ms
46,796 KB
testcase_26 AC 457 ms
47,112 KB
testcase_27 AC 501 ms
48,244 KB
testcase_28 AC 102 ms
40,140 KB
testcase_29 AC 106 ms
41,176 KB
testcase_30 AC 381 ms
46,848 KB
testcase_31 AC 472 ms
48,168 KB
testcase_32 AC 488 ms
48,216 KB
testcase_33 AC 491 ms
48,140 KB
testcase_34 AC 522 ms
48,224 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 sum = 0;
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
            sum += arr[i];
        }
        TreeSet<Integer> another = new TreeSet<>();
        for (int i = 1; i <= Math.sqrt(sum); i++) {
            if (sum % i != 0) {
                continue;
            }
            another.add(sum / i);
            int tmp = 0;
            boolean flag = true;
            int count = 0;
            for (int x : arr) {
                tmp += x;
                if (tmp > i) {
                    flag = false;
                    break;
                } else if (tmp == i) {
                    tmp = 0;
                    count++;
                }
            }
            if (flag) {
                System.out.println(count);
                return;
            }
        }
        for (int y : another) {
            int tmp = 0;
            boolean flag = true;
            int count = 0;
            for (int x : arr) {
                tmp += x;
                if (tmp > y) {
                    flag = false;
                    break;
                } else if (tmp == y) {
                    tmp = 0;
                    count++;
                }
            }
            if (flag) {
                System.out.println(count);
                return;
            }
        }
    }
}
0