結果

問題 No.1884 Sequence
ユーザー HimaHima
提出日時 2022-05-05 10:20:32
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 1,682 bytes
コンパイル時間 17,465 ms
コンパイル使用メモリ 201,612 KB
実行使用メモリ 12,172 KB
最終ジャッジ日時 2023-09-17 17:06:04
合計ジャッジ時間 15,397 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,328 KB
testcase_01 AC 1 ms
4,360 KB
testcase_02 AC 2 ms
4,360 KB
testcase_03 AC 2 ms
4,360 KB
testcase_04 AC 1 ms
4,360 KB
testcase_05 AC 1 ms
4,356 KB
testcase_06 AC 1 ms
4,360 KB
testcase_07 AC 2 ms
4,360 KB
testcase_08 WA -
testcase_09 AC 1 ms
4,360 KB
testcase_10 AC 104 ms
12,172 KB
testcase_11 AC 104 ms
12,168 KB
testcase_12 AC 11 ms
5,476 KB
testcase_13 AC 12 ms
5,480 KB
testcase_14 AC 10 ms
5,488 KB
testcase_15 AC 46 ms
9,864 KB
testcase_16 AC 72 ms
12,108 KB
testcase_17 AC 20 ms
7,792 KB
testcase_18 AC 29 ms
9,864 KB
testcase_19 AC 25 ms
7,792 KB
testcase_20 AC 39 ms
7,800 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 72 ms
12,108 KB
testcase_24 AC 71 ms
12,112 KB
testcase_25 AC 73 ms
12,108 KB
testcase_26 AC 75 ms
12,108 KB
testcase_27 AC 10 ms
5,484 KB
testcase_28 AC 12 ms
5,488 KB
testcase_29 AC 11 ms
5,488 KB
testcase_30 AC 13 ms
5,484 KB
testcase_31 AC 37 ms
7,792 KB
testcase_32 AC 68 ms
12,112 KB
testcase_33 AC 33 ms
12,108 KB
testcase_34 AC 33 ms
12,108 KB
testcase_35 AC 13 ms
5,496 KB
testcase_36 AC 27 ms
9,872 KB
testcase_37 AC 36 ms
12,172 KB
testcase_38 AC 31 ms
12,112 KB
testcase_39 AC 17 ms
7,772 KB
testcase_40 AC 20 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)
	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)
	for i := 1; i < len(ds); i++ {
		if ds[0] == 0 {
			if ds[i] > 0 {
				return "No"
			}
		} else {
			if ds[0] != ds[i] && Gcd(ds[0], ds[i]) == 1 {
				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