結果

問題 No.1233 割り切れない気持ち
ユーザー ccppjsrbccppjsrb
提出日時 2020-09-29 19:49:25
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 2,014 bytes
コンパイル時間 12,021 ms
コンパイル使用メモリ 213,960 KB
実行使用メモリ 14,636 KB
最終ジャッジ日時 2023-09-17 14:43:21
合計ジャッジ時間 16,118 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,580 KB
testcase_01 AC 3 ms
7,580 KB
testcase_02 AC 6 ms
7,584 KB
testcase_03 AC 8 ms
7,584 KB
testcase_04 AC 8 ms
7,584 KB
testcase_05 AC 6 ms
7,588 KB
testcase_06 AC 6 ms
7,588 KB
testcase_07 AC 30 ms
8,644 KB
testcase_08 AC 44 ms
10,456 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 28 ms
8,632 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 15 ms
7,908 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 15 ms
7,908 KB
testcase_21 AC 33 ms
7,908 KB
testcase_22 AC 33 ms
7,908 KB
testcase_23 AC 33 ms
7,912 KB
testcase_24 AC 33 ms
7,908 KB
testcase_25 AC 33 ms
7,908 KB
testcase_26 AC 33 ms
7,908 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 3 ms
7,584 KB
testcase_38 AC 15 ms
9,872 KB
testcase_39 WA -
testcase_40 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int64, n)
	mx := 200005
	cc := make([]int, mx)
	ss := make([]int64, mx)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt64(scanner)
	}
	sort.Slice(aa, func(i, j int) bool {
		return aa[i] < aa[j]
	})
	for i := 0; i < n; i++ {
		cc[aa[i]]++
		ss[aa[i]] += aa[i]
	}
	for i := 0; i < mx-1; i++ {
		cc[i+1] += cc[i]
		ss[i+1] += ss[i]
	}
	var ans int64
	used := map[int64]bool{}
	for i := 0; i < n; i++ {
		if used[aa[i]] {
			continue
		}
		c := int64(cc[aa[i]] - cc[aa[i]-1])
		for j := int64(0); j+aa[i] < int64(mx); j += aa[i] {
			if j > 1 {
				ans += c * ((ss[j+aa[i]-1] - ss[j-1]) - j*int64(cc[j+aa[i]-1]-cc[j-1]))
				continue
			}
			ans += c * ((ss[j+aa[i]-1]) - j*int64(cc[j+aa[i]-1]))
		}
		used[aa[i]] = true
	}
	fmt.Fprintln(writer, ans)
}
0