結果

問題 No.935 う し た ぷ に き あ く ん 笑 ビ - ム
ユーザー neko_the_shadowneko_the_shadow
提出日時 2020-02-10 09:43:01
言語 Go
(1.22.1)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 1,862 bytes
コンパイル時間 12,473 ms
コンパイル使用メモリ 211,960 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-08 12:48:26
合計ジャッジ時間 16,170 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 5 ms
6,676 KB
testcase_02 AC 5 ms
6,676 KB
testcase_03 AC 8 ms
6,676 KB
testcase_04 AC 13 ms
6,676 KB
testcase_05 AC 8 ms
6,676 KB
testcase_06 AC 8 ms
6,676 KB
testcase_07 AC 9 ms
6,676 KB
testcase_08 AC 27 ms
6,676 KB
testcase_09 AC 16 ms
6,676 KB
testcase_10 AC 17 ms
6,676 KB
testcase_11 AC 16 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 3 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 3 ms
6,676 KB
testcase_16 AC 3 ms
6,676 KB
testcase_17 AC 20 ms
6,676 KB
testcase_18 AC 16 ms
6,676 KB
testcase_19 AC 8 ms
6,676 KB
testcase_20 AC 22 ms
6,676 KB
testcase_21 AC 3 ms
6,676 KB
testcase_22 AC 6 ms
6,676 KB
testcase_23 AC 3 ms
6,676 KB
testcase_24 AC 3 ms
6,676 KB
testcase_25 AC 3 ms
6,676 KB
testcase_26 AC 3 ms
6,676 KB
testcase_27 AC 2 ms
6,676 KB
testcase_28 AC 3 ms
6,676 KB
testcase_29 AC 4 ms
6,676 KB
testcase_30 AC 2 ms
6,676 KB
testcase_31 AC 3 ms
6,676 KB
testcase_32 AC 3 ms
6,676 KB
testcase_33 AC 24 ms
6,676 KB
testcase_34 AC 17 ms
6,676 KB
testcase_35 AC 19 ms
6,676 KB
testcase_36 AC 9 ms
6,676 KB
testcase_37 AC 18 ms
6,676 KB
testcase_38 AC 7 ms
6,676 KB
testcase_39 AC 17 ms
6,676 KB
testcase_40 AC 18 ms
6,676 KB
testcase_41 AC 18 ms
6,676 KB
testcase_42 AC 20 ms
6,676 KB
testcase_43 AC 18 ms
6,676 KB
testcase_44 AC 4 ms
6,676 KB
testcase_45 AC 26 ms
6,676 KB
testcase_46 AC 3 ms
6,676 KB
testcase_47 AC 6 ms
6,676 KB
testcase_48 AC 15 ms
6,676 KB
testcase_49 AC 6 ms
6,676 KB
testcase_50 AC 15 ms
6,676 KB
testcase_51 AC 12 ms
6,676 KB
testcase_52 AC 11 ms
6,676 KB
testcase_53 AC 24 ms
6,676 KB
testcase_54 AC 10 ms
6,676 KB
testcase_55 AC 3 ms
6,676 KB
testcase_56 AC 16 ms
6,676 KB
testcase_57 AC 9 ms
6,676 KB
testcase_58 AC 2 ms
6,676 KB
testcase_59 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

func exec(stdin *Stdin, stdout *Stdout) {
	n := stdin.ReadInt()
	s := stdin.Read()
	a := []int{}
	for i := 0; i < n; i++ {
		a = append(a, stdin.ReadInt())
	}
	q := stdin.ReadInt()
	k := []int{}
	for i := 0; i < q; i++ {
		k = append(k, stdin.ReadInt())
	}

	// key = 倒せる数、エネルギー
	d := make([]int, n+1)
	for i := 1; i < n+1; i++ {
		d[i] = int(math.MaxInt32)
	}
	for i := 0; i < n; i++ {
		key := 0
		val := 0
		for j := i; j < n; j++ {
			if s[j] == 'E' {
				key++
			}
			val += a[j]
			d[key] = Min(d[key], val)
		}
	}

	for i := n - 1; i >= 0; i-- {
		key := 0
		val := 0
		for j := i; j >= 0; j-- {
			if s[j] == 'E' {
				key++
			}
			val += a[j]
			d[key] = Min(d[key], val)
		}
	}

	for i := 0; i < q; i++ {
		x := sort.Search(n+1, func(j int) bool {
			return d[j] > k[i]
		})
		stdout.Println(x - 1)
	}
}

func Min(a ...int) int {
	v := a[0]
	for i := 1; i < len(a); i++ {
		if a[i] < v {
			v = a[i]
		}
	}
	return v
}

func main() {
	stdout := NewStdout()
	defer stdout.Flush()
	exec(NewStdin(bufio.ScanWords), stdout)
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), int(math.MaxInt32))
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}
0