結果

問題 No.1884 Sequence
ユーザー Hima
提出日時 2022-05-05 10:29:26
言語 Go
(1.23.4)
結果
WA  
実行時間 -
コード長 1,713 bytes
コンパイル時間 12,141 ms
コンパイル使用メモリ 218,392 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-07-04 12:00:06
合計ジャッジ時間 14,398 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Solve(n int, a []int) string {
	//d := make(map[int]struct{})
	sort.Ints(a)
	//fmt.Println(a)
	var ds []int
	for i := 1; i < n; i++ {
		//d[a[i]-a[i-1]] = struct{}{}
		if a[i] > 0 && a[i-1] > 0 {
			ds = append(ds, a[i]-a[i-1])
		}
	}
	if len(ds) == 0 {
		return "Yes"
	}
	//var ds []int
	//for k := range d {
	//	ds = append(ds, k)
	//}
	sort.Ints(ds)
	//fmt.Println(ds)
	for i := 1; i < len(ds); i++ {
		if ds[0] == 0 {
			if ds[i] > 0 {
				return "No"
			}
		} else {
			if ds[0] != ds[i] && ds[i]%ds[0] != 0 {
				return "No"
			}
		}
	}

	var nz int
	for _, v := range a {
		if v == 0 {
			nz++
		}
	}
	var need int
	for i := 1; i < len(ds); i++ {
		if ds[0] > 0 {
			need += ds[i]/ds[0] - 1
		}
	}
	if nz >= need {
		return "Yes"
	} else {
		return "No"
	}
}

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)

	n := nextInt()
	a := nextIntSlice(n)
	ans := Solve(n, a)
	fmt.Println(ans)
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextIntSlice(n int) []int {
	s := make([]int, n)
	for i := range s {
		s[i] = nextInt()
	}
	return s
}

func Min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func Max(x, y int) int {
	if x < y {
		return y
	}
	return x
}

func Gcd(x, y int) int {
	if x == 0 {
		return y
	}
	if y == 0 {
		return x
	}
	/*
		if x < y {
			x, y = y, x
		}
	*/
	return Gcd(y, x%y)
}

func Lcm(x, y int) int {
	// x*yのオーバーフロー対策のため先にGcdで割る
	// Gcd(x, y)はxの約数のため割り切れる
	ret := x / Gcd(x, y)
	ret *= y
	return ret
}
0