結果

問題 No.1282 Display Elements
ユーザー c-yanc-yan
提出日時 2020-11-10 12:47:46
言語 Go
(1.22.1)
結果
AC  
実行時間 804 ms / 2,000 ms
コード長 1,499 bytes
コンパイル時間 11,859 ms
コンパイル使用メモリ 206,940 KB
実行使用メモリ 5,508 KB
最終ジャッジ日時 2023-09-29 23:31:25
合計ジャッジ時間 15,230 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 656 ms
5,504 KB
testcase_16 AC 119 ms
5,480 KB
testcase_17 AC 466 ms
5,492 KB
testcase_18 AC 189 ms
5,480 KB
testcase_19 AC 99 ms
5,508 KB
testcase_20 AC 95 ms
5,500 KB
testcase_21 AC 804 ms
5,500 KB
testcase_22 AC 539 ms
5,504 KB
testcase_23 AC 781 ms
5,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

func appendSorted(a []int, b int) []int {
	i := sort.Search(len(a), func(i int) bool { return a[i] >= b })
	a = append(a, b)
	if i == len(a) {
		return a
	}
	for j := len(a) - 1; j != i; j-- {
		a[j] = a[j-1]
	}
	a[i] = b
	return a
}

func main() {
	defer flush()

	N := readInt()
	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = readInt()
	}
	b := make([]int, N)
	for i := 0; i < N; i++ {
		b[i] = readInt()
	}
	sort.Ints(a)

	t0 := make([]int, 0, N)
	t1 := make([]int, 0, 1000)
	result := 0
	for i := 0; i < N; i++ {
		result += sort.Search(len(t0), func(j int) bool { return t0[j] >= a[i] })
		t1 = appendSorted(t1, b[i])
		result += sort.Search(len(t1), func(j int) bool { return t1[j] >= a[i] })
		if len(t1) == 1000 {
			t0 = append(t0, t1...)
			sort.Ints(t0)
			t1 = t1[:0]
		}
	}
	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