結果

問題 No.1492 01文字列と転倒
ユーザー 小野寺健
提出日時 2021-12-17 17:53:06
言語 Go
(1.23.4)
結果
MLE  
実行時間 -
コード長 1,120 bytes
コンパイル時間 15,660 ms
コンパイル使用メモリ 240,912 KB
実行使用メモリ 794,728 KB
最終ジャッジ日時 2024-09-14 19:06:32
合計ジャッジ時間 40,740 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 13 MLE * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
	"bufio"
	"os"
)

type Array3D struct {
	array [] int
	xsize, ysize, zsize int
}

func (this *Array3D) new(xsize int, ysize int, zsize int) {
	this.array = make([]int, xsize * ysize * zsize)
	this.xsize = xsize
	this.ysize = ysize
	this.zsize = zsize
}

func (this *Array3D) set(x int, y int, z int, val int) {
	this.array[x * (this.ysize * this.zsize) + y * (this.zsize) + z] = val
}

func (this *Array3D) get(x int, y int, z int) int {
	return this.array[x * (this.ysize * this.zsize) + y * (this.zsize) + z]
}

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
    defer w.Flush()
	var N, M int
	fmt.Fscan(r, &N, &M)
	dp := new(Array3D)
	dp.new(N+1, N+1, N*N+1)
	dp.set(0, 0, 0, 1)
	for i := 0; i <= N; i++ {
		for j := 0; j <= N; j++ {
			for k := 0; k <= N*N; k++ {
				if k+j <= N*N && i+1 <= N {
					dp.set(i+1, j, k+j, (dp.get(i+1, j, k+j) + dp.get(i, j, k)) % M)
				}
				if i >= j+1 && j+1 <= N {
					dp.set(i, j+1, k, (dp.get(i, j+1, k) + dp.get(i, j, k)) % M)
				}
			}
		}
	}
	for i := 0; i <= N*N; i++ {
		fmt.Fprintln(w, dp.get(N, N, i))
	}
}
0