結果

問題 No.944 煎っぞ!
ユーザー tentententen
提出日時 2023-02-16 13:34:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 197 ms / 3,000 ms
コード長 2,390 bytes
コンパイル時間 3,304 ms
コンパイル使用メモリ 82,992 KB
実行使用メモリ 56,380 KB
最終ジャッジ日時 2023-09-25 18:33:08
合計ジャッジ時間 11,035 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 158 ms
56,264 KB
testcase_01 AC 152 ms
55,788 KB
testcase_02 AC 158 ms
56,092 KB
testcase_03 AC 149 ms
55,428 KB
testcase_04 AC 162 ms
55,276 KB
testcase_05 AC 153 ms
56,380 KB
testcase_06 AC 167 ms
56,180 KB
testcase_07 AC 161 ms
56,028 KB
testcase_08 AC 147 ms
53,364 KB
testcase_09 AC 150 ms
56,176 KB
testcase_10 AC 53 ms
50,516 KB
testcase_11 AC 93 ms
52,532 KB
testcase_12 AC 94 ms
50,880 KB
testcase_13 AC 45 ms
49,400 KB
testcase_14 AC 101 ms
52,584 KB
testcase_15 AC 97 ms
52,676 KB
testcase_16 AC 44 ms
49,604 KB
testcase_17 AC 45 ms
49,312 KB
testcase_18 AC 105 ms
52,236 KB
testcase_19 AC 101 ms
52,348 KB
testcase_20 AC 152 ms
55,708 KB
testcase_21 AC 163 ms
55,716 KB
testcase_22 AC 159 ms
55,968 KB
testcase_23 AC 167 ms
56,344 KB
testcase_24 AC 159 ms
56,280 KB
testcase_25 AC 156 ms
56,184 KB
testcase_26 AC 167 ms
56,028 KB
testcase_27 AC 180 ms
55,668 KB
testcase_28 AC 45 ms
49,752 KB
testcase_29 AC 44 ms
47,356 KB
testcase_30 AC 165 ms
55,836 KB
testcase_31 AC 197 ms
56,252 KB
testcase_32 AC 176 ms
56,268 KB
testcase_33 AC 173 ms
55,920 KB
testcase_34 AC 156 ms
54,312 KB
権限があれば一括ダウンロードができます

ソースコード

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[] values = new int[n];
        int total = 0;
        for (int i = 0; i < n; i++) {
            values[i] = sc.nextInt();
            total += values[i];
        }
        ArrayList<Integer> targets = new ArrayList<>();
        for (int i = 1; i <= Math.sqrt(total); i++) {
            if (total % i == 0) {
                targets.add(i);
                targets.add(total / i);
            }
        }
        int ans = 1;
        for (int x : targets) {
            boolean enable = true;
            int current = 0;
            for (int y : values) {
                current += y;
                if (current > x) {
                    enable = false;
                    break;
                }
                if (current == x) {
                    current = 0;
                }
            }
            if (enable) {
                ans = Math.max(ans, total / x);
            }
        }
        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