結果

問題 No.1285 ゴミ捨て
ユーザー fmhrfmhr
提出日時 2020-11-13 21:46:23
言語 Go
(1.21.3)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,672 bytes
コンパイル時間 11,563 ms
コンパイル使用メモリ 209,924 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-19 07:15:54
合計ジャッジ時間 12,980 ms
ジャッジサーバーID
(参考情報)
judge15 / judge9
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 28 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 13 ms
4,376 KB
testcase_10 AC 24 ms
4,376 KB
testcase_11 AC 22 ms
4,376 KB
testcase_12 AC 17 ms
4,376 KB
testcase_13 AC 17 ms
4,376 KB
testcase_14 AC 27 ms
4,384 KB
testcase_15 AC 19 ms
4,376 KB
testcase_16 AC 6 ms
4,376 KB
testcase_17 AC 6 ms
4,380 KB
testcase_18 AC 5 ms
4,376 KB
testcase_19 AC 11 ms
4,380 KB
testcase_20 AC 5 ms
4,380 KB
testcase_21 AC 7 ms
4,376 KB
testcase_22 AC 29 ms
4,376 KB
testcase_23 AC 29 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

var sc = bufio.NewScanner(os.Stdin)
var buff []byte

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextFloat64() float64 {
	sc.Scan()
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextInts(n int) (r []int) {
	r = make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt64

func maxInt(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func minInt(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buff, bufio.MaxScanTokenSize*1024)
	log.SetFlags(log.Lshortfile)
}

func main() {
	N := nextInt()
	A := nextInts(N)
	sort.Ints(A)
	ans := 1
	for i := 0; i < N-1; i++ {
		for j := i + 1; j < N; j++ {
			if A[i]+1 < A[j] {
				ans = maxInt(ans, j-i)
				break
			} else if j == N-1 {
				ans = maxInt(ans, j-i+1)
			}
		}
	}
	fmt.Println(ans)
}
0