結果

問題 No.1884 Sequence
ユーザー HimaHima
提出日時 2022-05-05 10:29:26
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 1,713 bytes
コンパイル時間 12,724 ms
コンパイル使用メモリ 211,712 KB
実行使用メモリ 12,168 KB
最終ジャッジ日時 2023-09-17 17:18:37
合計ジャッジ時間 16,180 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,356 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 103 ms
12,168 KB
testcase_11 AC 103 ms
12,168 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 9 ms
5,488 KB
testcase_15 AC 46 ms
9,860 KB
testcase_16 AC 71 ms
12,112 KB
testcase_17 AC 19 ms
7,788 KB
testcase_18 AC 29 ms
9,864 KB
testcase_19 AC 24 ms
7,796 KB
testcase_20 AC 37 ms
7,796 KB
testcase_21 AC 27 ms
7,780 KB
testcase_22 AC 40 ms
7,800 KB
testcase_23 AC 71 ms
12,108 KB
testcase_24 AC 72 ms
12,108 KB
testcase_25 AC 74 ms
12,112 KB
testcase_26 AC 75 ms
12,112 KB
testcase_27 AC 11 ms
5,488 KB
testcase_28 AC 11 ms
5,484 KB
testcase_29 AC 11 ms
5,484 KB
testcase_30 AC 13 ms
5,488 KB
testcase_31 AC 37 ms
7,796 KB
testcase_32 AC 68 ms
12,112 KB
testcase_33 AC 33 ms
12,108 KB
testcase_34 AC 32 ms
12,108 KB
testcase_35 AC 13 ms
5,496 KB
testcase_36 AC 27 ms
9,868 KB
testcase_37 AC 36 ms
12,168 KB
testcase_38 AC 31 ms
12,108 KB
testcase_39 AC 17 ms
7,776 KB
testcase_40 AC 19 ms
7,780 KB
testcase_41 AC 60 ms
10,028 KB
testcase_42 AC 60 ms
10,028 KB
権限があれば一括ダウンロードができます

ソースコード

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