結果

問題 No.362 門松ナンバー
ユーザー ccppjsrbccppjsrb
提出日時 2023-04-19 23:38:33
言語 Go
(1.22.1)
結果
AC  
実行時間 60 ms / 3,000 ms
コード長 2,694 bytes
コンパイル時間 13,066 ms
コンパイル使用メモリ 227,456 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2024-04-23 02:57:47
合計ジャッジ時間 14,826 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
5,248 KB
testcase_01 AC 19 ms
5,248 KB
testcase_02 AC 18 ms
5,376 KB
testcase_03 AC 11 ms
5,376 KB
testcase_04 AC 5 ms
5,376 KB
testcase_05 AC 27 ms
5,376 KB
testcase_06 AC 47 ms
5,376 KB
testcase_07 AC 27 ms
5,376 KB
testcase_08 AC 35 ms
5,376 KB
testcase_09 AC 49 ms
5,888 KB
testcase_10 AC 60 ms
5,888 KB
testcase_11 AC 59 ms
6,016 KB
testcase_12 AC 59 ms
5,476 KB
testcase_13 AC 58 ms
5,504 KB
testcase_14 AC 57 ms
6,016 KB
testcase_15 AC 60 ms
5,888 KB
testcase_16 AC 58 ms
6,144 KB
testcase_17 AC 56 ms
5,376 KB
testcase_18 AC 59 ms
5,888 KB
testcase_19 AC 42 ms
5,632 KB
testcase_20 AC 59 ms
5,620 KB
testcase_21 AC 8 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

var iost *Iost

type Iost struct {
	Scanner *bufio.Scanner
	Writer  *bufio.Writer
}

func NewIost(fp io.Reader, wfp io.Writer) *Iost {
	const BufSize = 2000005
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, BufSize), BufSize)
	return &Iost{Scanner: scanner, Writer: bufio.NewWriter(wfp)}
}
func (i *Iost) Text() string {
	if !i.Scanner.Scan() {
		panic("scan failed")
	}
	return i.Scanner.Text()
}
func (i *Iost) Atoi(s string) int                 { x, _ := strconv.Atoi(s); return x }
func (i *Iost) GetNextInt() int                   { return i.Atoi(i.Text()) }
func (i *Iost) Atoi64(s string) int64             { x, _ := strconv.ParseInt(s, 10, 64); return x }
func (i *Iost) GetNextInt64() int64               { return i.Atoi64(i.Text()) }
func (i *Iost) Atof64(s string) float64           { x, _ := strconv.ParseFloat(s, 64); return x }
func (i *Iost) GetNextFloat64() float64           { return i.Atof64(i.Text()) }
func (i *Iost) Print(x ...interface{})            { fmt.Fprint(i.Writer, x...) }
func (i *Iost) Printf(s string, x ...interface{}) { fmt.Fprintf(i.Writer, s, x...) }
func (i *Iost) Println(x ...interface{})          { fmt.Fprintln(i.Writer, x...) }
func isLocal() bool                               { return os.Getenv("NICKEL") == "BACK" }
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	if isLocal() {
		fp, _ = os.Open(os.Getenv("WELL_EVERYBODY_LIES_TOO_MUCH"))
	}
	iost = NewIost(fp, wfp)
	defer func() {
		iost.Writer.Flush()
	}()
	solve()
}
func solve() {
	t := iost.GetNextInt()
	for i := 0; i < t; i++ {
		testcase()
	}
}
func testcase() {
	k := iost.GetNextInt()
	more := sort.Search(math.MaxInt64, func(x int) bool {
		return f(x) >= k
	})
	iost.Println(more)
}
func f(x int) int {
	if x < 100 {
		return 0
	}
	ans := 0
	xx := make([]int, 0)
	for x > 0 {
		xx = append(xx, x%10)
		x /= 10
	}
	l := 0
	n := len(xx)
	r := n - 1
	for l < r {
		xx[l], xx[r] = xx[r], xx[l]
		l++
		r--
	}
	dp := make([][2][10][10]int, n+1)
	dp[n][0][0][0] = 1
	for i := n - 1; i >= 0; i-- {
		used := n - 1 - i
		for j := 0; j < 2; j++ {
			for k := 0; k < 10; k++ {
				for l := 0; l < 10; l++ {
					for m := 0; m < 10; m++ {
						tj := 0
						if xx[i]-j < m {
							tj = 1
						}
						if used >= 2 && !g(m, k, l) {
							continue
						}
						dp[i][tj][m][k] += dp[i+1][j][k][l]
						if m == 0 || used < 2 {
							continue
						}
						if i > 0 || tj == 0 {
							ans += dp[i+1][j][k][l]
						}
					}
				}
			}
		}
	}
	return ans
}
func g(a, b, c int) bool {
	return a != b && b != c && a != c && ((a < b && b > c) || (a > b && b < c))
}
0