用户输出
48
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#20450 | #1040. 1-04G. nocriz的爆搜题 | Accepted | 100 | 422 ms | 476 K | C++ / 2.9 K | q3540555 | 2019-07-22 15:23:19 |
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define spause() system("pause")
using namespace std;
typedef long long llong;
typedef unsigned long long ullong;
typedef pair<int, int> prdd;
typedef map<int, int> mpdd;
const int dinf = 0x7fffffff;
const llong llinf = 0x7fffffffffffffff;
const int p = 998244353;
struct save {
int n;
int ua;
};
int n, m, c, ans = 0;
int pc[12][12], mp, pw[12];
save sve[12][12];
llong starttime;
void argp(int x, int y, int rg);
void bfs(int ts, int rg);
int main() {
pw[0] = 1;
for (int i = 1; i < 12; i++) pw[i] = i * pw[i - 1];
scanf("%d%d%d", &n, &m, &c);
if (n + m > c + 1)
printf("0");
else {
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) scanf("%d", &pc[i][j]);
starttime = clock();
if (n + m == c + 1) {
vector<int> usd;
for (int i = 2; i <= c + 1; i++) {
int tn = 0;
for (int j = 1; j <= n; j++)
if (i - j > 0 && i - j <= m)
if (pc[j][i - j] != 0 && pc[j][i - j] != tn)
if (tn == 0) {
tn = pc[j][i - j];
for (int a = 0; a < usd.size(); a++)
if (tn == usd.at(a))
goto baded;
usd.push_back(tn);
} else
goto baded;
}
printf("%d", pw[c - usd.size()]);
} else {
bfs(2, 0);
printf("%d", ans);
}
}
// cout << "\nDebug Info: " << clock() - starttime << " ms passed!\n";
spause();
return 0;
baded:
printf("0");
// cout << "\nDebug Info: " << clock() - starttime << " ms passed!\n";
spause();
return 0;
}
void argp(int x, int y, int rg) {
if (y > m)
argp(x + 1, y - 1, rg);
else if (x > n || y <= 0)
bfs(x + y + 1, rg);
else
for (int i = 1; i <= rg + 1 && i < c; i++) {
if (sve[x][y].ua >> i & 1)
continue;
sve[x][y].n = i;
sve[x][y].ua ^= (1 << i);
argp(x + 1, y - 1, max(i, rg));
sve[x][y].ua ^= (1 << i);
}
}
void bfs(int ts, int rg) {
if (ts >= n + m) {
sve[n][m].n = rg + 1;
rg++;
int ct[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
vector<int> us;
for (int x = 1; x <= n; x++)
for (int y = 1; y <= m; y++) {
int xyn = sve[x][y].n;
if (pc[x][y] != 0 && pc[x][y] != ct[xyn]) {
if (ct[xyn] == 0) {
ct[xyn] = pc[x][y];
for (int i = 0; i < us.size(); i++)
if (ct[xyn] == us.at(i))
return;
us.push_back(ct[xyn]);
} else
return;
}
}
int nans = pw[c - us.size()] / pw[c - rg];
ans = (ans + nans) % p;
return;
}
for (int x = 1; x <= n; x++)
if (ts - x > 0 && ts - x <= m)
sve[x][ts - x].ua = sve[x - 1][ts - x].ua | sve[x][ts - x - 1].ua;
argp(1, ts - 1, rg);
}
用户输出
3628800
系统信息
Exited with return code 0
用户输出
0
系统信息
Exited with return code 0
用户输出
3628800
系统信息
Exited with return code 0
用户输出
3628800
系统信息
Exited with return code 0
用户输出
1
系统信息
Exited with return code 0
用户输出
1
系统信息
Exited with return code 0
用户输出
0
系统信息
Exited with return code 0
用户输出
1
系统信息
Exited with return code 0
用户输出
144420861
系统信息
Exited with return code 0
用户输出
6881280
系统信息
Exited with return code 0
用户输出
3628800
系统信息
Exited with return code 0
用户输出
0
系统信息
Exited with return code 0
用户输出
5040
系统信息
Exited with return code 0
用户输出
0
系统信息
Exited with return code 0
用户输出
0
系统信息
Exited with return code 0
用户输出
40320
系统信息
Exited with return code 0
用户输出
0
系统信息
Exited with return code 0
用户输出
0
系统信息
Exited with return code 0
用户输出
0
系统信息
Exited with return code 0
用户输出
5040
系统信息
Exited with return code 0
用户输出
0
系统信息
Exited with return code 0
用户输出
0
系统信息
Exited with return code 0
用户输出
0
系统信息
Exited with return code 0
用户输出
0
系统信息
Exited with return code 0
用户输出
40320
系统信息
Exited with return code 0
用户输出
5040
系统信息
Exited with return code 0
用户输出
5040
系统信息
Exited with return code 0
用户输出
362880
系统信息
Exited with return code 0
用户输出
40320
系统信息
Exited with return code 0
用户输出
0
系统信息
Exited with return code 0
用户输出
0
系统信息
Exited with return code 0
用户输出
3374784
系统信息
Exited with return code 0
用户输出
3374784
系统信息
Exited with return code 0
用户输出
3374784
系统信息
Exited with return code 0
用户输出
3374784
系统信息
Exited with return code 0
用户输出
33747840
系统信息
Exited with return code 0
用户输出
3374784
系统信息
Exited with return code 0
用户输出
144420861
系统信息
Exited with return code 0
用户输出
445964257
系统信息
Exited with return code 0
用户输出
144420861
系统信息
Exited with return code 0
用户输出
0
系统信息
Exited with return code 0
用户输出
365783040
系统信息
Exited with return code 0
用户输出
12714240
系统信息
Exited with return code 0
用户输出
0
系统信息
Exited with return code 0
用户输出
5040
系统信息
Exited with return code 0
用户输出
190330560
系统信息
Exited with return code 0