結果

問題 No.1884 Sequence
ユーザー HimaHima
提出日時 2022-05-05 10:28:49
言語 Go
(1.21.3)
結果
WA  
実行時間 -
コード長 1,709 bytes
コンパイル時間 12,957 ms
コンパイル使用メモリ 205,256 KB
実行使用メモリ 24,800 KB
最終ジャッジ日時 2023-09-17 17:18:06
合計ジャッジ時間 18,689 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
権限があれば一括ダウンロードができます

ソースコード

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