結果
問題 | No.1823 Tricolor Dango |
ユーザー | Hima |
提出日時 | 2022-05-15 23:06:59 |
言語 | Go (1.22.1) |
結果 |
AC
|
実行時間 | 19 ms / 2,000 ms |
コード長 | 2,164 bytes |
コンパイル時間 | 12,403 ms |
コンパイル使用メモリ | 213,520 KB |
実行使用メモリ | 7,964 KB |
最終ジャッジ日時 | 2023-10-11 12:31:08 |
合計ジャッジ時間 | 14,436 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,348 KB |
testcase_01 | AC | 15 ms
7,948 KB |
testcase_02 | AC | 14 ms
7,948 KB |
testcase_03 | AC | 14 ms
7,952 KB |
testcase_04 | AC | 9 ms
5,656 KB |
testcase_05 | AC | 8 ms
5,660 KB |
testcase_06 | AC | 9 ms
5,660 KB |
testcase_07 | AC | 8 ms
5,592 KB |
testcase_08 | AC | 7 ms
5,600 KB |
testcase_09 | AC | 8 ms
5,584 KB |
testcase_10 | AC | 8 ms
5,608 KB |
testcase_11 | AC | 8 ms
5,588 KB |
testcase_12 | AC | 8 ms
5,600 KB |
testcase_13 | AC | 8 ms
5,532 KB |
testcase_14 | AC | 8 ms
5,532 KB |
testcase_15 | AC | 7 ms
5,528 KB |
testcase_16 | AC | 4 ms
4,348 KB |
testcase_17 | AC | 5 ms
4,352 KB |
testcase_18 | AC | 8 ms
5,528 KB |
testcase_19 | AC | 19 ms
5,540 KB |
testcase_20 | AC | 8 ms
5,524 KB |
testcase_21 | AC | 10 ms
5,692 KB |
testcase_22 | AC | 14 ms
7,908 KB |
testcase_23 | AC | 9 ms
5,672 KB |
testcase_24 | AC | 10 ms
5,692 KB |
testcase_25 | AC | 13 ms
7,964 KB |
ソースコード
package main import ( "bufio" "container/heap" "fmt" "os" "sort" "strconv" ) var sc = bufio.NewScanner(os.Stdin) type PriorityQueue []int func (pq PriorityQueue) Len() int { return len(pq) } func (pq PriorityQueue) Less(i, j int) bool { return pq[i] > pq[j] } func (pq PriorityQueue) Swap(i, j int) { pq[i], pq[j] = pq[j], pq[i] } func (pq *PriorityQueue) Push(item interface{}) { *pq = append(*pq, item.(int)) } func (pq *PriorityQueue) Pop() interface{} { es := *pq // EdgeのSlice n := len(es) item := es[n-1] *pq = es[0 : n-1] return item } func firstSolve(t int, n []int, a [][]int) []string { var ans []string for k := 0; k < t; k++ { q := &PriorityQueue{} heap.Init(q) for _, v := range a[k] { heap.Push(q, v) } for q.Len() >= 3 { var b []int for j := 0; j < 3; j++ { b = append(b, heap.Pop(q).(int)) } sort.Ints(b) b[1] -= b[0] b[2] -= b[0] if b[1] > 0 { heap.Push(q, b[1]) } if b[2] > 0 { heap.Push(q, b[2]) } } if q.Len() == 0 { ans = append(ans, "Yes") } else { ans = append(ans, "No") } } return ans } func solve(t int, n []int, a [][]int) []string { var ans []string for k := 0; k < t; k++ { var mx, s int for _, v := range a[k] { mx = Max(mx, v) s += v } if s%3 == 0 && s/3 >= mx { ans = append(ans, "Yes") } else { ans = append(ans, "No") } } return ans } func main() { buf := make([]byte, 1024*1024) sc.Buffer(buf, bufio.MaxScanTokenSize) sc.Split(bufio.ScanWords) t := nextInt() var n []int var a [][]int for i := 0; i < t; i++ { ni := nextInt() n = append(n, ni) a = append(a, nextIntSlice(ni)) } ans := solve(t, n, a) out := bufio.NewWriter(os.Stdout) defer out.Flush() for _, v := range ans { fmt.Fprintln(out, v) } } 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 Abs(x int) int { if x < 0 { return -x } return x } 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 }