QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#734344#5810. Doubly-sorted Gridzbrc10 13ms14272kbC++141.8kb2024-11-11 09:07:412024-11-11 09:07:42

Judging History

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

  • [2024-11-11 09:07:42]
  • 评测
  • 测评结果:10
  • 用时:13ms
  • 内存:14272kb
  • [2024-11-11 09:07:41]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 1.1e6 + 10, mod = 1e4 + 7;
int dp[2][N];
int n, m;
char c[30][30];
vector<int> v;
int tmp[N];
int sol()
{
    scanf("%d%d",&n,&m);getchar();
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
            scanf("%c",&c[i][j]);
        getchar();
    }
    memset(dp,0,sizeof dp);
    dp[0][(1 << m) - 1] = 1;
    for (int i = 0; i < 26; i++)
    {
        int ri=(i&1),ti=(i&1)^1;
        for (int S = 0; S < (1 << n + m); S++)
        {
            if (__builtin_popcount(S) != m)
                continue;
            dp[ti][S] = dp[ri][S];
            v.clear();
            int x = 0, y = m;
            for (int j = 0; j < n + m - 1; j++)
            {
                ((S >> j) & 1) ? y-- : x++;
                if (((S >> j) & 3) == 2)
                {
                    if (c[x][y] == '.' or c[x][y] == i + 'a')
                        v.push_back(3 << j);
                }
            }
            int sz = v.size();
            for (int j = 1; j < (1 << sz); j++)
            {
                tmp[j] = (j == (j & (-j)) ? v[__builtin_ctz(j)] : tmp[j & (-j)] ^ tmp[j ^ (j & (-j))]);
                int op = __builtin_popcount(j) & 1;
                if (op)
                    dp[ti][S] += dp[ti][S ^ tmp[j]];
                else
                    dp[ti][S] -= dp[ti][S ^ tmp[j]];
                if (dp[ti][S] < 0)
                    dp[ti][S] += mod;
                if (dp[ti][S] >= mod)
                    dp[ti][S] -= mod;
            }
        }
    }
    return dp[0][((1 << m) - 1) << n];
}
int main()
{
    int T;
    scanf("%d",&T);
    for (int i = 1; i <= T; i++)
    {
        printf("Case #%d: %d\n", i, sol());
    }
    return 0;
}

详细

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 13ms
memory: 14272kb

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: 0
Time Limit Exceeded

Test #2:

score: 0
Time Limit Exceeded

input:

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

output:


result: