結果

問題 No.885 アマリクエリ
ユーザー MiyamonYMiyamonY
提出日時 2019-09-29 02:34:13
言語 Go
(1.22.1)
結果
AC  
実行時間 859 ms / 2,000 ms
コード長 1,064 bytes
コンパイル時間 12,163 ms
コンパイル使用メモリ 227,120 KB
実行使用メモリ 7,944 KB
最終ジャッジ日時 2024-04-14 07:10:50
合計ジャッジ時間 16,807 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 859 ms
7,944 KB
testcase_01 AC 389 ms
7,812 KB
testcase_02 AC 240 ms
7,684 KB
testcase_03 AC 193 ms
6,940 KB
testcase_04 AC 195 ms
6,944 KB
testcase_05 AC 164 ms
6,940 KB
testcase_06 AC 156 ms
6,944 KB
testcase_07 AC 10 ms
6,944 KB
testcase_08 AC 162 ms
6,940 KB
testcase_09 AC 398 ms
7,812 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 4 ms
6,940 KB
testcase_14 AC 4 ms
6,944 KB
testcase_15 AC 4 ms
6,944 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 AC 3 ms
6,940 KB
testcase_18 AC 3 ms
6,944 KB
testcase_19 AC 1 ms
6,944 KB
testcase_20 AC 3 ms
6,944 KB
testcase_21 AC 1 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 (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

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)
}

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	p := make(pq, n)
	sum := 0
	for i := 0; i < n; i++ {
		p[i] = nextInt()
		sum += p[i]
	}
	heap.Init(&p)
	q := nextInt()
	for i := 0; i < q; i++ {
		x := nextInt()
		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