結果
| 問題 | 
                            No.944 煎っぞ!
                             | 
                    
| コンテスト | |
| ユーザー | 
                             neko_the_shadow
                         | 
                    
| 提出日時 | 2019-12-13 09:45:04 | 
| 言語 | Go  (1.23.4)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 8 ms / 3,000 ms | 
| コード長 | 962 bytes | 
| コンパイル時間 | 11,803 ms | 
| コンパイル使用メモリ | 227,272 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-26 20:44:48 | 
| 合計ジャッジ時間 | 12,610 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 35 | 
ソースコード
package main
import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)
func main() {
	n := readInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = readInt()
	}
	sum := 0
	for _, v := range a {
		sum += v
	}
	factors := []int{}
	for i := 1; i*i <= sum; i++ {
		if sum%i == 0 {
			j := sum / i
			factors = append(factors, i)
			factors = append(factors, j)
		}
	}
	sort.Ints(factors)
	for _, x := range factors {
		if ok(a, x) {
			fmt.Println(sum / x)
			break
		}
	}
}
func ok(a []int, x int) bool {
	sum := 0
	for _, v := range a {
		sum += v
		if sum == x {
			sum = 0
		} else if x < sum {
			return false
		}
	}
	return true
}
var stdin *bufio.Scanner
func read() string {
	if stdin == nil {
		stdin = bufio.NewScanner(os.Stdin)
		stdin.Split(bufio.ScanWords)
		stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), int(math.MaxInt32))
	}
	stdin.Scan()
	return stdin.Text()
}
func readInt() int {
	n, _ := strconv.Atoi(read())
	return n
}
            
            
            
        
            
neko_the_shadow