编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#5110 #1040. 1-04G. nocriz的爆搜题 Accepted 100 836 ms 304 K C++ 11 (NOI) / 2.1 K nocriz🦆 2019-06-27 20:35:04
显示原始代码
#include <set>
#include <queue>
#include <cmath>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#define debug(x) cerr << #x << '=' << x << endl
#define set0(x) memset(x, 0, sizeof(x))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
template <typename T>
void read(T &x) {
    x = 0;
    char ch = getchar();
    ll f = 1;
    while (!isdigit(ch)) {
        if (ch == '-')
            f *= -1;
        ch = getchar();
    }
    while (isdigit(ch)) {
        x = x * 10 + ch - 48;
        ch = getchar();
    }
    x *= f;
}
int mod = 998244353;
inline int mul(int x, int y) { return 1ll * x * y % mod; }
int add(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }
int sub(int x, int y) { return x - y < 0 ? x - y + mod : x - y; }
int sq(int x) { return 1ll * x * x % mod; }
int pow(int a, int b) { return b == 0 ? 1 : (b & 1 ? mul(a, sq(pow(a, b / 2))) : sq(pow(a, b / 2))); }
int n, m, c;
int apr[15][15], mp[15][15], cnt[15], ans;
int rpn[15][15];
void dfs(int a, int b, int cways) {
    // cout<<a<<' '<<b<<' '<<cways<<endl;
    if (a == n + 1 && b == 1) {
        ans = add(ans, cways);
        return;
    }
    if (mp[a][b]) {
        apr[a][b] = 1 << mp[a][b];
        if ((apr[a][b] & apr[a - 1][b]) | (apr[a][b] & apr[a][b - 1]))
            return;
        apr[a][b] |= apr[a - 1][b] | apr[a][b - 1];
        if (b != m)
            dfs(a, b + 1, cways);
        else
            dfs(a + 1, 1, cways);
        return;
    }
    int cv = -1, ccho = 0;
    for (int i = 1; i <= c; i++) {
        if (cnt[i] == 0) {
            ccho += 1;
            cv = i;
        } else {
            apr[a][b] = 1 << i;
            if ((1 << i) & rpn[a][b])
                continue;
            if ((apr[a][b] & apr[a - 1][b]) | (apr[a][b] & apr[a][b - 1]))
                continue;
            apr[a][b] |= apr[a - 1][b] | apr[a][b - 1];
            cnt[i] += 1;
            if (b != m)
                dfs(a, b + 1, cways);
            else
                dfs(a + 1, 1, cways);
            cnt[i] -= 1;
        }
    }
    // cout<<cv<<endl;
    if (cv != -1 && ((1 << cv) & rpn[a][b]) == 0) {
        apr[a][b] = 1 << cv;
        apr[a][b] |= apr[a - 1][b] | apr[a][b - 1];
        cnt[cv] += 1;
        if (b != m)
            dfs(a, b + 1, mul(cways, ccho));
        else
            dfs(a + 1, 1, mul(cways, ccho));
        cnt[cv] -= 1;
    }
}

int main() {
    read(n);
    read(m);
    read(c);
    if (n + m - 1 > c) {
        cout << 0 << endl;
        return 0;
    }
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++) {
            cin >> mp[i][j];
            cnt[mp[i][j]] += 1;
            if (mp[i][j]) {
                for (int ii = 1; ii <= i; ii++)
                    for (int jj = 1; jj <= j; jj++) rpn[ii][jj] |= 1 << mp[i][j];
            }
        }
    dfs(1, 1, 1);
    cout << ans << endl;
    return 0;
}
子任务 #1
Accepted
得分:100
测试点 #1
Accepted
得分:100
用时:3 ms
内存:300 KiB

输入文件(1.in

2 2 4
0 0
0 0

答案文件(1.out

48

用户输出

48

系统信息

Exited with return code 0
测试点 #2
Accepted
得分:100
用时:5 ms
内存:252 KiB

输入文件(2.in

2 2 4
1 2
2 1

答案文件(2.out

0

用户输出

0

系统信息

Exited with return code 0
测试点 #3
Accepted
得分:100
用时:37 ms
内存:300 KiB

输入文件(3.in

5 6 10
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0

答案文件(3.out

3628800

用户输出

3628800

系统信息

Exited with return code 0
测试点 #4
Accepted
得分:100
用时:4 ms
内存:264 KiB

输入文件(4.in

2 6 10
1 2 3 4 5 6
0 0 0 0 0 0

答案文件(4.out

4096

用户输出

4096

系统信息

Exited with return code 0
测试点 #5
Accepted
得分:100
用时:3 ms
内存:172 KiB

输入文件(5.in

6 6 10
0 0 0 0 0 0
0 0 0 2 0 0
2 0 1 0 0 0
0 0 0 0 5 0
0 0 0 3 0 0
0 0 0 4 0 9

答案文件(5.out

0

用户输出

0

系统信息

Exited with return code 0
测试点 #6
Accepted
得分:100
用时:3 ms
内存:252 KiB

输入文件(6.in

3 3 10
0 0 2
2 0 0
0 3 10

答案文件(6.out

6300

用户输出

6300

系统信息

Exited with return code 0
测试点 #7
Accepted
得分:100
用时:8 ms
内存:252 KiB

输入文件(7.in

3 8 10
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0

答案文件(7.out

3628800

用户输出

3628800

系统信息

Exited with return code 0
测试点 #8
Accepted
得分:100
用时:3 ms
内存:300 KiB

输入文件(8.in

1 10 10
0 0 0 0 0 0 0 0 0 0

答案文件(8.out

3628800

用户输出

3628800

系统信息

Exited with return code 0
测试点 #9
Accepted
得分:100
用时:3 ms
内存:252 KiB

输入文件(9.in

5 5 10
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7
4 5 6 7 8
6 7 8 9 10

答案文件(9.out

1

用户输出

1

系统信息

Exited with return code 0
测试点 #10
Accepted
得分:100
用时:3 ms
内存:220 KiB

输入文件(10.in

5 6 10
1 2 3 4 5 6
2 3 4 5 6 7
3 4 5 6 7 8
4 5 6 7 8 9
5 6 7 8 9 10

答案文件(10.out

1

用户输出

1

系统信息

Exited with return code 0
测试点 #11
Accepted
得分:100
用时:4 ms
内存:276 KiB

输入文件(11.in

5 6 10
1 2 3 4 5 6
2 3 4 5 6 7
3 4 5 6 7 8
4 5 6 7 8 9
5 6 7 8 9 9

答案文件(11.out

0

用户输出

0

系统信息

Exited with return code 0
测试点 #12
Accepted
得分:100
用时:3 ms
内存:304 KiB

输入文件(12.in

4 4 10
1 2 3 4
5 6 7 8
6 7 8 9
7 8 9 10

答案文件(12.out

1

用户输出

1

系统信息

Exited with return code 0
测试点 #13
Accepted
得分:100
用时:3 ms
内存:276 KiB

输入文件(13.in

4 4 10
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 4

答案文件(13.out

144420861

用户输出

144420861

系统信息

Exited with return code 0
测试点 #14
Accepted
得分:100
用时:3 ms
内存:252 KiB

输入文件(14.in

1 5 5
0 0 0 0 0

答案文件(14.out

120

用户输出

120

系统信息

Exited with return code 0
测试点 #15
Accepted
得分:100
用时:3 ms
内存:300 KiB

输入文件(15.in

2 6 10
0 0 3 0 0 0
0 0 0 0 0 1

答案文件(15.out

6881280

用户输出

6881280

系统信息

Exited with return code 0
测试点 #16
Accepted
得分:100
用时:3 ms
内存:300 KiB

输入文件(16.in

3 3 2
0 0 0
1 1 1
2 2 2

答案文件(16.out

0

用户输出

0

系统信息

Exited with return code 0
测试点 #17
Accepted
得分:100
用时:3 ms
内存:220 KiB

输入文件(17.in

2 2 3
0 0
0 0

答案文件(17.out

6

用户输出

6

系统信息

Exited with return code 0
测试点 #18
Accepted
得分:100
用时:3 ms
内存:216 KiB

输入文件(18.in

1 1 1
0

答案文件(18.out

1

用户输出

1

系统信息

Exited with return code 0
测试点 #19
Accepted
得分:100
用时:3 ms
内存:124 KiB

输入文件(19.in

1 1 2
0

答案文件(19.out

2

用户输出

2

系统信息

Exited with return code 0
测试点 #20
Accepted
得分:100
用时:3 ms
内存:276 KiB

输入文件(20.in

1 1 3
0

答案文件(20.out

3

用户输出

3

系统信息

Exited with return code 0
测试点 #21
Accepted
得分:100
用时:3 ms
内存:220 KiB

输入文件(21.in

1 6 4
4 0 0 0 0 0

答案文件(21.out

0

用户输出

0

系统信息

Exited with return code 0
测试点 #22
Accepted
得分:100
用时:3 ms
内存:220 KiB

输入文件(22.in

1 10 10
0 0 0 0 0 0 0 0 0 0

答案文件(22.out

3628800

用户输出

3628800

系统信息

Exited with return code 0
测试点 #23
Accepted
得分:100
用时:4 ms
内存:220 KiB

输入文件(23.in

1 5 10
0 0 0 8 2

答案文件(23.out

336

用户输出

336

系统信息

Exited with return code 0
测试点 #24
Accepted
得分:100
用时:4 ms
内存:220 KiB

输入文件(24.in

5 6 10
0 0 3 1 0 0
0 0 0 0 0 0
0 7 0 1 0 0
0 0 0 0 10 0
0 0 0 0 0 0

答案文件(24.out

0

用户输出

0

系统信息

Exited with return code 0
测试点 #25
Accepted
得分:100
用时:181 ms
内存:252 KiB

输入文件(25.in

5 6 10
0 0 0 0 0 0
1 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
9 0 0 4 0 0

答案文件(25.out

5040

用户输出

5040

系统信息

Exited with return code 0
测试点 #26
Accepted
得分:100
用时:20 ms
内存:276 KiB

输入文件(26.in

5 6 10
0 0 0 0 0 3
0 0 0 0 0 0
0 0 0 7 0 0
0 0 10 0 0 0
0 0 0 0 0 0

答案文件(26.out

0

用户输出

0

系统信息

Exited with return code 0
测试点 #27
Accepted
得分:100
用时:4 ms
内存:220 KiB

输入文件(27.in

5 6 10
0 0 6 0 0 5
0 7 0 0 0 0
0 0 0 4 0 0
0 0 0 0 0 0
0 0 0 2 1 1

答案文件(27.out

0

用户输出

0

系统信息

Exited with return code 0
测试点 #28
Accepted
得分:100
用时:38 ms
内存:248 KiB

输入文件(28.in

5 6 10
0 0 0 0 0 0
4 0 0 0 0 0
1 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0

答案文件(28.out

40320

用户输出

40320

系统信息

Exited with return code 0
测试点 #29
Accepted
得分:100
用时:4 ms
内存:236 KiB

输入文件(29.in

5 6 10
0 0 9 0 0 5
0 1 0 6 0 8
0 0 0 0 0 0
0 6 0 0 0 0
0 0 0 0 0 6

答案文件(29.out

0

用户输出

0

系统信息

Exited with return code 0
测试点 #30
Accepted
得分:100
用时:3 ms
内存:172 KiB

输入文件(30.in

5 6 10
7 0 8 0 0 0
7 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0

答案文件(30.out

0

用户输出

0

系统信息

Exited with return code 0
测试点 #31
Accepted
得分:100
用时:137 ms
内存:252 KiB

输入文件(31.in

5 6 10
0 0 0 0 0 0
0 0 0 6 0 0
0 0 0 0 2 0
0 0 0 0 0 0
3 0 0 0 0 0

答案文件(31.out

0

用户输出

0

系统信息

Exited with return code 0
测试点 #32
Accepted
得分:100
用时:27 ms
内存:304 KiB

输入文件(32.in

5 6 10
0 0 0 5 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 9 0 0
0 0 0 1 0 0

答案文件(32.out

5040

用户输出

5040

系统信息

Exited with return code 0
测试点 #33
Accepted
得分:100
用时:9 ms
内存:260 KiB

输入文件(33.in

5 6 10
0 0 0 1 0 0
0 0 0 0 7 0
0 0 0 0 0 0
9 0 0 0 0 2
0 0 0 0 0 2

答案文件(33.out

0

用户输出

0

系统信息

Exited with return code 0
测试点 #34
Accepted
得分:100
用时:4 ms
内存:180 KiB

输入文件(34.in

5 6 10
0 0 0 0 0 4
0 0 0 0 0 0
0 5 4 0 3 0
0 0 0 8 0 3
0 0 0 0 0 0

答案文件(34.out

0

用户输出

0

系统信息

Exited with return code 0
测试点 #35
Accepted
得分:100
用时:4 ms
内存:252 KiB

输入文件(35.in

5 6 10
0 0 0 0 0 4
0 0 0 7 0 0
0 0 0 0 0 0
8 0 0 0 0 8
0 0 0 0 2 7

答案文件(35.out

0

用户输出

0

系统信息

Exited with return code 0
测试点 #36
Accepted
得分:100
用时:6 ms
内存:200 KiB

输入文件(36.in

5 6 10
0 0 8 0 0 0
0 0 0 0 0 0
7 0 0 0 0 0
0 0 0 0 0 0
0 0 0 5 8 0

答案文件(36.out

0

用户输出

0

系统信息

Exited with return code 0
测试点 #37
Accepted
得分:100
用时:38 ms
内存:300 KiB

输入文件(37.in

5 6 10
0 0 0 0 0 0
0 0 8 0 0 3
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0

答案文件(37.out

40320

用户输出

40320

系统信息

Exited with return code 0
测试点 #38
Accepted
得分:100
用时:8 ms
内存:272 KiB

输入文件(38.in

5 6 10
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 6 0
0 8 0 0 0 7
0 0 0 0 0 0

答案文件(38.out

5040

用户输出

5040

系统信息

Exited with return code 0
测试点 #39
Accepted
得分:100
用时:25 ms
内存:232 KiB

输入文件(39.in

5 6 10
0 0 0 0 0 0
0 0 0 0 0 0
3 0 0 0 9 0
0 0 0 0 0 0
0 0 0 2 0 0

答案文件(39.out

5040

用户输出

5040

系统信息

Exited with return code 0
测试点 #40
Accepted
得分:100
用时:38 ms
内存:232 KiB

输入文件(40.in

5 6 10
0 0 1 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0

答案文件(40.out

362880

用户输出

362880

系统信息

Exited with return code 0
测试点 #41
Accepted
得分:100
用时:26 ms
内存:300 KiB

输入文件(41.in

5 6 10
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 8 0 0
0 0 0 0 0 0
0 8 0 7 0 0

答案文件(41.out

40320

用户输出

40320

系统信息

Exited with return code 0
测试点 #42
Accepted
得分:100
用时:3 ms
内存:296 KiB

输入文件(42.in

4 4 7
0 0 0 0
1 0 0 0
0 0 0 0
0 0 0 1

答案文件(42.out

0

用户输出

0

系统信息

Exited with return code 0
测试点 #43
Accepted
得分:100
用时:3 ms
内存:176 KiB

输入文件(43.in

5 5 1
0 1 0 0 1
0 0 0 0 0
1 0 0 0 0
0 0 0 0 0
0 0 1 0 1

答案文件(43.out

0

用户输出

0

系统信息

Exited with return code 0
测试点 #44
Accepted
得分:100
用时:3 ms
内存:180 KiB

输入文件(44.in

3 3 10
0 0 0
8 0 0
4 7 0

答案文件(44.out

46872

用户输出

46872

系统信息

Exited with return code 0
测试点 #45
Accepted
得分:100
用时:3 ms
内存:172 KiB

输入文件(45.in

3 3 10
0 0 0
6 0 10
0 7 0

答案文件(45.out

37800

用户输出

37800

系统信息

Exited with return code 0
测试点 #46
Accepted
得分:100
用时:3 ms
内存:252 KiB

输入文件(46.in

3 3 10
3 0 0
0 0 0
4 0 0

答案文件(46.out

374976

用户输出

374976

系统信息

Exited with return code 0
测试点 #47
Accepted
得分:100
用时:4 ms
内存:264 KiB

输入文件(47.in

3 3 10
0 0 0
0 0 0
1 5 9

答案文件(47.out

46872

用户输出

46872

系统信息

Exited with return code 0
测试点 #48
Accepted
得分:100
用时:3 ms
内存:220 KiB

输入文件(48.in

3 3 10
0 0 0
0 0 0
0 1 0

答案文件(48.out

3374784

用户输出

3374784

系统信息

Exited with return code 0
测试点 #49
Accepted
得分:100
用时:4 ms
内存:232 KiB

输入文件(49.in

3 3 10
0 0 0
0 0 0
3 0 0

答案文件(49.out

3374784

用户输出

3374784

系统信息

Exited with return code 0
测试点 #50
Accepted
得分:100
用时:3 ms
内存:180 KiB

输入文件(50.in

3 3 10
0 0 0
0 0 0
0 5 0

答案文件(50.out

3374784

用户输出

3374784

系统信息

Exited with return code 0
测试点 #51
Accepted
得分:100
用时:3 ms
内存:252 KiB

输入文件(51.in

3 3 10
0 0 0
0 0 0
0 0 1

答案文件(51.out

3374784

用户输出

3374784

系统信息

Exited with return code 0
测试点 #52
Accepted
得分:100
用时:3 ms
内存:220 KiB

输入文件(52.in

3 3 10
0 0 6
5 0 0
0 0 0

答案文件(52.out

324576

用户输出

324576

系统信息

Exited with return code 0
测试点 #53
Accepted
得分:100
用时:3 ms
内存:172 KiB

输入文件(53.in

3 3 10
0 0 0
0 0 0
0 0 0

答案文件(53.out

33747840

用户输出

33747840

系统信息

Exited with return code 0
测试点 #54
Accepted
得分:100
用时:3 ms
内存:220 KiB

输入文件(54.in

3 3 10
0 0 0
0 2 0
7 0 0

答案文件(54.out

312480

用户输出

312480

系统信息

Exited with return code 0
测试点 #55
Accepted
得分:100
用时:3 ms
内存:252 KiB

输入文件(55.in

3 3 10
0 9 7
0 7 0
9 0 0

答案文件(55.out

8400

用户输出

8400

系统信息

Exited with return code 0
测试点 #56
Accepted
得分:100
用时:3 ms
内存:180 KiB

输入文件(56.in

3 3 10
0 10 0
0 0 0
0 0 0

答案文件(56.out

3374784

用户输出

3374784

系统信息

Exited with return code 0
测试点 #57
Accepted
得分:100
用时:3 ms
内存:220 KiB

输入文件(57.in

3 3 10
0 2 0
0 0 8
0 0 0

答案文件(57.out

374976

用户输出

374976

系统信息

Exited with return code 0
测试点 #58
Accepted
得分:100
用时:3 ms
内存:220 KiB

输入文件(58.in

3 3 10
0 3 0
0 4 0
0 0 0

答案文件(58.out

374976

用户输出

374976

系统信息

Exited with return code 0
测试点 #59
Accepted
得分:100
用时:5 ms
内存:220 KiB

输入文件(59.in

4 4 10
9 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0

答案文件(59.out

144420861

用户输出

144420861

系统信息

Exited with return code 0
测试点 #60
Accepted
得分:100
用时:4 ms
内存:252 KiB

输入文件(60.in

4 4 10
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0

答案文件(60.out

445964257

用户输出

445964257

系统信息

Exited with return code 0
测试点 #61
Accepted
得分:100
用时:5 ms
内存:300 KiB

输入文件(61.in

4 4 10
0 0 0 0
0 0 0 5
0 0 0 0
0 0 0 0

答案文件(61.out

144420861

用户输出

144420861

系统信息

Exited with return code 0
测试点 #62
Accepted
得分:100
用时:5 ms
内存:252 KiB

输入文件(62.in

4 5 10
0 0 0 0 0
0 0 0 0 0
0 0 6 3 0
0 0 0 0 6

答案文件(62.out

0

用户输出

0

系统信息

Exited with return code 0
测试点 #63
Accepted
得分:100
用时:44 ms
内存:228 KiB

输入文件(63.in

5 5 10
0 0 0 0 0
3 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0

答案文件(63.out

365783040

用户输出

365783040

系统信息

Exited with return code 0
测试点 #64
Accepted
得分:100
用时:4 ms
内存:180 KiB

输入文件(64.in

3 5 10
0 0 0 0 0
0 0 0 8 10
0 9 0 0 0

答案文件(64.out

12714240

用户输出

12714240

系统信息

Exited with return code 0
测试点 #65
Accepted
得分:100
用时:9 ms
内存:252 KiB

输入文件(65.in

4 7 10
0 7 0 0 0 0 0
0 0 0 0 9 0 0
0 0 0 0 0 0 9
0 8 0 0 0 0 0

答案文件(65.out

0

用户输出

0

系统信息

Exited with return code 0
测试点 #66
Accepted
得分:100
用时:8 ms
内存:220 KiB

输入文件(66.in

3 8 10
2 0 0 0 4 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 8 0 0 0

答案文件(66.out

5040

用户输出

5040

系统信息

Exited with return code 0
测试点 #67
Accepted
得分:100
用时:7 ms
内存:300 KiB

输入文件(67.in

3 6 10
0 0 3 0 0 0
0 0 0 0 0 1
0 0 0 0 0 0

答案文件(67.out

190330560

用户输出

190330560

系统信息

Exited with return code 0
测试点 #68
Accepted
得分:100
用时:3 ms
内存:300 KiB

输入文件(68.in

3 3 10
0 0 0
0 0 0
3 0 0

答案文件(68.out

3374784

用户输出

3374784

系统信息

Exited with return code 0