結果

問題 No.885 アマリクエリ
ユーザー MiyamonYMiyamonY
提出日時 2019-09-29 02:29:14
言語 Go
(1.22.1)
結果
TLE  
実行時間 -
コード長 896 bytes
コンパイル時間 15,684 ms
コンパイル使用メモリ 226,164 KB
実行使用メモリ 8,092 KB
最終ジャッジ日時 2024-04-14 07:10:32
合計ジャッジ時間 37,248 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 TLE -
testcase_03 TLE -
testcase_04 TLE -
testcase_05 AC 1,554 ms
7,948 KB
testcase_06 AC 636 ms
7,956 KB
testcase_07 AC 1,039 ms
7,960 KB
testcase_08 AC 1,217 ms
7,840 KB
testcase_09 TLE -
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 1 ms
6,944 KB
testcase_13 AC 25 ms
6,940 KB
testcase_14 AC 25 ms
6,940 KB
testcase_15 AC 26 ms
6,944 KB
testcase_16 AC 26 ms
6,940 KB
testcase_17 AC 25 ms
6,944 KB
testcase_18 AC 25 ms
6,944 KB
testcase_19 AC 13 ms
6,944 KB
testcase_20 AC 14 ms
6,940 KB
testcase_21 AC 13 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// Package main provides
//
// File:  main.go
// Author: ymiyamoto
//
// Created on Sun Sep 29 02:05:32 2019
//
package main

import (
	"container/heap"
	"fmt"
)

type pq []int

func (p pq) Len() int {
	return len(p)
}

func (p pq) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pq) Less(i, j int) bool {
	return p[i] > p[j]
}

func (p *pq) Pop() interface{} {
	n := len(*p)
	x := (*p)[n-1]
	*p = (*p)[:n-1]
	return x
}

func (p *pq) Push(x interface{}) {
	v, _ := x.(int)
	*p = append(*p, v)
}

func main() {
	var n int
	fmt.Scan(&n)
	p := make(pq, n)
	sum := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&p[i])
		sum += p[i]
	}
	heap.Init(&p)

	var q int
	fmt.Scan(&q)
	for i := 0; i < q; i++ {
		var x int
		fmt.Scan(&x)

		n, _ := heap.Pop(&p).(int)
		for x <= n {
			heap.Push(&p, n%x)
			sum -= n
			sum += n % x
			n, _ = heap.Pop(&p).(int)
		}
		heap.Push(&p, n)
		fmt.Println(sum)
	}

}
0