QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#115106#5810. Doubly-sorted GridGeZhiyuan30 ✓8704ms398880kbC++141.6kb2023-06-24 16:47:242023-06-24 16:47:25

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-24 16:47:25]
  • 评测
  • 测评结果:30
  • 用时:8704ms
  • 内存:398880kb
  • [2023-06-24 16:47:24]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

const int N = 10 + 5, K = 30, S = 2e5 + 5, Mod = 10007;

inline void upd(int &x, int dx){
	x = x + dx;
	if(x >= Mod) x -= Mod;
}

array<int, N> tmp;

int n = 0, m = 0, tot = 0, dp[K][S][N] = {}, tr[S][N] = {};
char str[N][N] = {};
map<array<int, N> , int> id;
array<int, N> state[S] = {};

inline void dfs(int x){
	if(x <= n) for(int y = 0 ; y <= tmp[x - 1] ; y ++){
		tmp[x] = y;
		dfs(x + 1);
	}
	else{
		tot ++;
		id[tmp] = tot, state[tot] = tmp;
	}
}

inline void init(){
	n = m = tot = 0;
	memset(str, 0, sizeof(str));
	memset(dp, 0, sizeof(dp)), memset(tr, 0, sizeof(tr));
	map<array<int, N> , int>().swap(id);
	memset(state, 0, sizeof(state));
}

inline void solve(int cas){
	scanf("%d %d", &n, &m);
	for(int x = 1 ; x <= n ; x ++) scanf("%s", str[x] + 1);
	tmp.fill(0);
	tmp[0] = m;
	dfs(1);
	for(int s = 1 ; s <= tot ; s ++) for(int x = 1 ; x <= n ; x ++){
		tmp = state[s];
		if(tmp[x] < tmp[x - 1]){
			tmp[x] ++;
			tr[s][x] = id[tmp];
		}
	}
	dp[0][1][1] = 1;
	for(int k = 0 ; k < 26 ; k ++) for(int s = 1 ; s <= tot ; s ++){
		tmp = state[s];
		for(int x = 1 ; x <= n ; x ++){
			upd(dp[k][s][x + 1], dp[k][s][x]);
			if(tr[s][x]){
				int t = tr[s][x], y = tmp[x] + 1;
				if(str[x][y] == '.' || str[x][y] - 'a' == k) upd(dp[k][t][x], dp[k][s][x]);
			}
		}
		upd(dp[k + 1][s][1], dp[k][s][n + 1]);
	}
	printf("Case #%d: %d\n", cas, dp[26][tot][1]);
}

int T = 0;

int main(){
	scanf("%d", &T);
	for(int i = 1 ; i <= T ; i ++) init(), solve(i);
	return 0;
}

詳細信息

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 1168ms
memory: 378864kb

input:

40
4 4
....
....
....
....
4 4
abcd
bcde
cdef
defg
4 4
bbcc
ccde
cdef
deef
4 4
....
....
.r..
..e.
3 4
....
....
...g
1 3
f..
2 2
.b
bb
2 3
...
..f
4 4
....
....
..t.
..d.
3 3
.gn
...
...
4 4
...a
...b
...c
...d
4 4
...b
..bb
.bbb
bbbb
4 4
a...
.b..
..c.
...d
3 3
c..
glw
..w
1 4
....
1 3
d.v
4 2
..
...

output:

Case #1: 7285
Case #2: 1
Case #3: 1
Case #4: 0
Case #5: 718
Case #6: 231
Case #7: 2
Case #8: 686
Case #9: 0
Case #10: 3500
Case #11: 330
Case #12: 14
Case #13: 4096
Case #14: 2756
Case #15: 3737
Case #16: 19
Case #17: 8175
Case #18: 3737
Case #19: 7279
Case #20: 256
Case #21: 23
Case #22: 7569
Case ...

result:

ok 40 lines

Subtask #2:

score: 20
Accepted

Test #2:

score: 20
Accepted
time: 8704ms
memory: 398880kb

input:

40
5 10
..........
..........
..........
..........
..........
10 10
....a.....
....c.....
....g.....
....j.....
....l.....
....m.....
....n.....
....q.....
....t.....
....v.....
10 10
..........
..........
..........
..........
..........
..........
..........
..........
...ok.....
..........
9 10
...

output:

Case #1: 8791
Case #2: 7220
Case #3: 0
Case #4: 2510
Case #5: 4299
Case #6: 1663
Case #7: 981
Case #8: 1430
Case #9: 8814
Case #10: 2877
Case #11: 2124
Case #12: 0
Case #13: 4311
Case #14: 4458
Case #15: 8699
Case #16: 3727
Case #17: 14
Case #18: 5478
Case #19: 7922
Case #20: 6789
Case #21: 1252
Cas...

result:

ok 40 lines

Extra Test:

score: 0
Extra Test Passed