結果
| 問題 |
No.944 煎っぞ!
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2022-08-04 09:51:07 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 289 ms / 3,000 ms |
| コード長 | 1,697 bytes |
| コンパイル時間 | 2,267 ms |
| コンパイル使用メモリ | 78,428 KB |
| 実行使用メモリ | 51,496 KB |
| 最終ジャッジ日時 | 2024-09-14 05:59:24 |
| 合計ジャッジ時間 | 10,384 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 35 |
ソースコード
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();
}
}
tenten