結果

問題 No.116 門松列(1)
ユーザー tyochiai
提出日時 2015-01-18 15:23:00
言語 Go
(1.23.4)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 961 bytes
コンパイル時間 13,856 ms
コンパイル使用メモリ 231,192 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-25 00:58:00
合計ジャッジ時間 14,723 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
	"math"
	"sort"
)

func MaxInt(x ...int) int {
	ret := x[0]
	for i := 1; i < len(x); i++ {
		ret = int(math.Max(float64(ret), float64(x[i])))
	}
	return ret
}

func MinInt(x ...int) int {
	ret := x[0]
	for i := 1; i < len(x); i++ {
		ret = int(math.Min(float64(ret), float64(x[i])))
	}
	return ret
}

func AbsInt(x int) int {
	return int(math.Abs(float64(x)))
}

func SortInt(x ...int) {
	sort.Sort(sort.IntSlice(x))
}

func SortReverseInt(x ...int) {
	sort.Sort(sort.Reverse(sort.IntSlice(x)))
}

func resolve(N int, A []int) int {
	cnt := 0

	for i := 1; i < N-1; i++ {
		if A[i-1] == A[i] || A[i] == A[i+1] || A[i-1] == A[i+1] {
			continue
		}

		a := make([]int, 3)
		copy(a, A[i-1:i+2])

		SortInt(a...)
		if a[1] == A[i] {
			continue
		}
		cnt += 1
	}

	return cnt
}

func main() {
	var N int

	fmt.Scanf("%d\n", &N)
	A := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &A[i])
	}

	fmt.Println(resolve(N, A))
}
0