結果

問題 No.1644 Eight Digits
ユーザー scrappyscrappy
提出日時 2022-10-11 12:38:12
言語 Go
(1.22.1)
結果
AC  
実行時間 4 ms / 1,000 ms
コード長 734 bytes
コンパイル時間 13,062 ms
コンパイル使用メモリ 209,704 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-07 13:55:07
合計ジャッジ時間 14,652 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,380 KB
testcase_01 AC 4 ms
4,380 KB
testcase_02 AC 4 ms
4,500 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 4 ms
4,380 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 3 ms
4,384 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 4 ms
4,380 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 4 ms
4,376 KB
testcase_21 AC 4 ms
4,376 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 4 ms
4,376 KB
testcase_25 AC 3 ms
4,380 KB
testcase_26 AC 3 ms
4,380 KB
testcase_27 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
)

type Stack[T any] []T

func New[T any]() Stack[T] {
	return make(Stack[T], 0)
}

func (s *Stack[T]) Push(x T) {
	(*s) = append((*s), x)
}

func (s *Stack[T]) Pop() T {
	v := (*s)[len(*s)-1]
	(*s) = (*s)[:len(*s)-1]
	return v
}

type EightRec struct {
	d     int /* 0..7 桁 */
	value int
	mask  int
}

func main() {
	var K int
	fmt.Scan(&K)

	count := 0

	stack := New[EightRec]()
	stack.Push(EightRec{0, 0, 0})
	for len(stack) > 0 {
		e := stack.Pop()
		if e.d < 8 {
			for m := 1; m <= 8; m++ {
				if e.mask&(1<<m) == 0 {
					e1 := EightRec{e.d + 1, e.value*10 + m, e.mask | (1 << m)}
					stack.Push(e1)
				}
			}
		} else {
			if e.value%K == 0 {
				count++
			}
		}
	}

	fmt.Println(count)
}
0