結果

問題 No.189 SUPER HAPPY DAY
ユーザー aru aruaru aru
提出日時 2020-09-06 21:13:37
言語 Go
(1.22.1)
結果
AC  
実行時間 41 ms / 5,000 ms
コード長 1,881 bytes
コンパイル時間 11,006 ms
コンパイル使用メモリ 203,292 KB
実行使用メモリ 14,276 KB
最終ジャッジ日時 2023-08-19 14:19:46
合計ジャッジ時間 12,587 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,520 KB
testcase_01 AC 2 ms
5,004 KB
testcase_02 AC 1 ms
5,004 KB
testcase_03 AC 2 ms
5,004 KB
testcase_04 AC 3 ms
5,064 KB
testcase_05 AC 3 ms
4,936 KB
testcase_06 AC 2 ms
4,940 KB
testcase_07 AC 2 ms
5,000 KB
testcase_08 AC 3 ms
4,940 KB
testcase_09 AC 3 ms
5,000 KB
testcase_10 AC 2 ms
5,000 KB
testcase_11 AC 3 ms
5,008 KB
testcase_12 AC 2 ms
4,940 KB
testcase_13 AC 25 ms
7,612 KB
testcase_14 AC 32 ms
9,152 KB
testcase_15 AC 27 ms
8,020 KB
testcase_16 AC 27 ms
8,304 KB
testcase_17 AC 31 ms
9,372 KB
testcase_18 AC 25 ms
7,800 KB
testcase_19 AC 39 ms
10,760 KB
testcase_20 AC 15 ms
5,100 KB
testcase_21 AC 17 ms
5,820 KB
testcase_22 AC 5 ms
4,940 KB
testcase_23 AC 21 ms
7,992 KB
testcase_24 AC 21 ms
7,992 KB
testcase_25 AC 41 ms
14,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

var dp [2][210][2010][2]int

const mod = int(1e9 + 9)

func makeDP(s string, a int) {
	n := len(s)
	dp[a][0][0][1] = 1
	for i := 0; i < n; i++ {
		for j := 0; j < 2000; j++ {
			for k := 0; k < 2; k++ {
				if k == 0 {
					for b := 0; b < 10; b++ {
						dp[a][i+1][j+b][k] += dp[a][i][j][k]
						dp[a][i+1][j+b][k] %= mod
					}
				} else {
					t := int(s[i] - '0')
					for b := 0; b < t; b++ {
						dp[a][i+1][j+b][0] += dp[a][i][j][1]
						dp[a][i+1][j+b][0] %= mod
					}
					dp[a][i+1][j+t][1] += dp[a][i][j][1]
					dp[a][i+1][j+t][1] %= mod
				}
			}
		}
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	s, t := getString(), getString()
	makeDP(s, 0)
	makeDP(t, 1)
	ans := 0
	for i := 1; i <= 2000; i++ {
		x := dp[0][len(s)][i][0] + dp[0][len(s)][i][1]
		y := dp[1][len(t)][i][0] + dp[1][len(t)][i][1]
		ans += x * y % mod
		ans %= mod
	}
	out(ans)
}
0