結果

問題 No.1623 三角形の制作
ユーザー c-yanc-yan
提出日時 2021-07-24 12:25:11
言語 Go
(1.22.1)
結果
AC  
実行時間 365 ms / 2,000 ms
コード長 2,042 bytes
コンパイル時間 11,990 ms
コンパイル使用メモリ 208,048 KB
実行使用メモリ 137,896 KB
最終ジャッジ日時 2023-09-26 23:35:32
合計ジャッジ時間 17,570 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 352 ms
130,524 KB
testcase_03 AC 342 ms
133,692 KB
testcase_04 AC 349 ms
134,880 KB
testcase_05 AC 365 ms
132,448 KB
testcase_06 AC 322 ms
131,608 KB
testcase_07 AC 344 ms
137,896 KB
testcase_08 AC 324 ms
133,704 KB
testcase_09 AC 349 ms
130,056 KB
testcase_10 AC 351 ms
133,708 KB
testcase_11 AC 348 ms
135,776 KB
testcase_12 AC 13 ms
5,556 KB
testcase_13 AC 16 ms
5,560 KB
testcase_14 AC 14 ms
5,564 KB
testcase_15 AC 38 ms
9,856 KB
testcase_16 AC 38 ms
9,860 KB
testcase_17 AC 38 ms
9,856 KB
testcase_18 AC 40 ms
9,860 KB
testcase_19 AC 18 ms
7,780 KB
testcase_20 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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 gg[i] == 0 {
			continue
		}
		for j := 0; j < 3001; j++ {
			if bb[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, gg[i]*bb[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