結果

問題 No.1492 01文字列と転倒
ユーザー 小野寺健小野寺健
提出日時 2021-12-17 17:53:06
言語 Go
(1.22.1)
結果
MLE  
実行時間 -
コード長 1,120 bytes
コンパイル時間 12,946 ms
コンパイル使用メモリ 211,736 KB
実行使用メモリ 807,224 KB
最終ジャッジ日時 2023-10-12 20:46:38
合計ジャッジ時間 40,656 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 MLE -
testcase_03 MLE -
testcase_04 MLE -
testcase_05 MLE -
testcase_06 MLE -
testcase_07 MLE -
testcase_08 MLE -
testcase_09 AC 2 ms
4,336 KB
testcase_10 AC 1 ms
4,364 KB
testcase_11 AC 1 ms
4,368 KB
testcase_12 AC 1 ms
4,368 KB
testcase_13 AC 2 ms
4,364 KB
testcase_14 MLE -
testcase_15 AC 4 ms
4,364 KB
testcase_16 AC 40 ms
14,100 KB
testcase_17 MLE -
testcase_18 AC 46 ms
16,172 KB
testcase_19 AC 2 ms
4,364 KB
testcase_20 AC 29 ms
11,996 KB
testcase_21 AC 1,750 ms
487,184 KB
testcase_22 AC 40 ms
14,100 KB
testcase_23 AC 17 ms
6,560 KB
権限があれば一括ダウンロードができます

ソースコード

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