結果

問題 No.190 Dry Wet Moist
ユーザー aru aruaru aru
提出日時 2020-09-06 21:29:44
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 1,452 bytes
コンパイル時間 11,224 ms
コンパイル使用メモリ 209,160 KB
実行使用メモリ 9,296 KB
最終ジャッジ日時 2023-08-19 14:20:20
合計ジャッジ時間 13,892 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
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 AC 75 ms
9,276 KB
testcase_24 WA -
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	a := getInts(2 * N)
	sort.Ints(a)

	wet := 0
	n := 0
	m := len(a) - 1
	for n < m {
		if a[m]+a[n] > 0 {
			wet++
			n++
			m--
		} else {
			n++
		}
	}
	dry := 0
	n = 0
	m = len(a) - 1
	for n < m {
		if a[m]+a[n] < 0 {
			dry++
			n++
			m--
		} else {
			m--
		}
	}

	x := make(map[int]int)
	for _, v := range a {
		x[abs(v)]++
	}
	moist := 0
	for _, e := range x {
		moist += e / 2
	}
	out(dry, wet, moist)
}
0