結果

問題 No.1015 おつりは要らないです
ユーザー aru aruaru aru
提出日時 2020-09-22 09:53:54
言語 Go
(1.22.1)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 2,365 bytes
コンパイル時間 13,974 ms
コンパイル使用メモリ 220,624 KB
実行使用メモリ 6,912 KB
最終ジャッジ日時 2024-04-29 06:19:42
合計ジャッジ時間 14,876 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 104 ms
6,912 KB
testcase_11 AC 106 ms
6,912 KB
testcase_12 AC 100 ms
6,912 KB
testcase_13 AC 105 ms
6,912 KB
testcase_14 AC 112 ms
6,912 KB
testcase_15 AC 103 ms
6,912 KB
testcase_16 AC 105 ms
6,912 KB
testcase_17 AC 109 ms
6,912 KB
testcase_18 AC 104 ms
6,912 KB
testcase_19 AC 103 ms
6,912 KB
testcase_20 AC 88 ms
6,912 KB
testcase_21 AC 88 ms
6,912 KB
testcase_22 AC 88 ms
6,912 KB
testcase_23 AC 84 ms
6,912 KB
testcase_24 AC 90 ms
6,912 KB
testcase_25 AC 89 ms
6,912 KB
testcase_26 AC 88 ms
6,912 KB
testcase_27 AC 86 ms
6,912 KB
testcase_28 AC 85 ms
6,912 KB
testcase_29 AC 87 ms
6,912 KB
testcase_30 AC 1 ms
5,376 KB
testcase_31 AC 11 ms
5,632 KB
testcase_32 AC 12 ms
5,632 KB
testcase_33 AC 22 ms
6,400 KB
testcase_34 AC 1 ms
5,376 KB
testcase_35 AC 1 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"container/heap"
	"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
}

//---------------------------------------------
// priority queue
//---------------------------------------------
type pqi struct{ a int }

type priorityQueue []pqi

func (pq priorityQueue) Len() int            { return len(pq) }
func (pq priorityQueue) Swap(i, j int)       { pq[i], pq[j] = pq[j], pq[i] }
func (pq priorityQueue) Less(i, j int) bool  { return pq[i].a > pq[j].a }
func (pq *priorityQueue) Push(x interface{}) { *pq = append(*pq, x.(pqi)) }
func (pq *priorityQueue) Pop() interface{} {
	x := (*pq)[len(*pq)-1]
	*pq = (*pq)[0 : len(*pq)-1]
	return x
}

func calc(Z, Y int) bool {
	for Z != 0 {
		if len(pq) == 0 {
			return true
		}
		v := heap.Pop(&pq).(pqi).a
		n := v / Y
		m := v % Y
		if n == 0 {
			Z--
		} else {
			if n <= Z {
				Z -= n
				v = m
			} else {
				v -= Z * Y
				Z = 0
			}
			if m != 0 {
				heap.Push(&pq, pqi{v})
			}
		}
	}
	return false
}

var pq priorityQueue

func main() {
	sc.Split(bufio.ScanWords)
	N, X, Y, Z := getInt(), getInt(), getInt(), getInt()
	pq = priorityQueue{}
	for i := 0; i < N; i++ {
		a := getInt()
		heap.Push(&pq, pqi{a + 1})
	}

	// out(pq)
	if calc(Z, 10000) == true {
		out("Yes")
		return
	}
	// out(pq)
	if calc(Y, 5000) == true {
		out("Yes")
		return
	}
	// out(pq)
	if calc(X, 1000) == true {
		out("Yes")
		return
	}
	// out(pq)
	if len(pq) == 0 {
		out("Yes")
		return
	}
	out("No")
}
0