結果

問題 No.1623 三角形の制作
ユーザー c-yanc-yan
提出日時 2021-07-24 12:23:04
言語 Go
(1.22.1)
結果
RE  
実行時間 -
コード長 2,038 bytes
コンパイル時間 15,882 ms
コンパイル使用メモリ 207,300 KB
実行使用メモリ 147,240 KB
最終ジャッジ日時 2023-09-26 23:31:06
合計ジャッジ時間 24,279 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

// BIT stands for binary indexed tree.
type BIT []int

func newBIT(n int) BIT {
	return make([]int, n)
}

func (bit BIT) add(i, v int) {
	for i++; i <= len(bit); i += i & -i {
		bit[i-1] += v
	}
}

func (bit BIT) sum(i int) int {
	result := 0
	for i++; i > 0; i -= i & -i {
		result += bit[i-1]
	}
	return result
}

func (bit BIT) query(start int, stop int) int {
	return bit.sum(stop-1) - bit.sum(start-1)
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func main() {
	defer flush()

	n := readInt()
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = readInt()
	}
	g := make([]int, n)
	for i := 0; i < n; i++ {
		g[i] = readInt()
	}
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}

	rr := make([]int, 3001)
	for i := 0; i < n; i++ {
		rr[r[i]]++
	}
	gg := make([]int, 3001)
	for i := 0; i < n; i++ {
		gg[g[i]]++
	}
	bb := make([]int, 3001)
	for i := 0; i < n; i++ {
		bb[b[i]]++
	}

	gb := make([][]int, 3001)
	for i := 0; i < 3001; i++ {
		if g[i] == 0 {
			continue
		}
		for j := 0; j < 3001; j++ {
			if b[j] == 0 {
				continue
			}
			gb[max(i, j)] = append(gb[max(i, j)], i<<12+j)
		}
	}

	result := 0
	bit := newBIT(6001)
	for i := 0; i < 3001; i++ {
		for _, x := range gb[i] {
			i := x >> 12
			j := x & 4095
			bit.add(i+j, g[i]*b[j])
		}
		result += rr[i] * bit.query(i+1, 6001)

	}
	println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

var stdoutWriter = bufio.NewWriter(os.Stdout)

func flush() {
	stdoutWriter.Flush()
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdoutWriter, args...)
}
0