用户输出
4
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#20448 | #1038. 1-04E. zzj & liaoy 想要去摄影 | Accepted | 100 | 117 ms | 1748 K | C++ / 1.8 K | q3540555 | 2019-07-22 15:22:56 |
#include <map>
#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;
const int dinf = 0x7fffffff;
const llong llinf = 0x7fffffffffffffff;
const int way[4][2] = { { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 } };
struct cao {
bool vd, fnd[1024];
int pic;
};
struct bfnt {
int f, s, ti;
};
int n, m, res = -1, ans = 0, picno = 0;
vector<bfnt> bfsn, tmp;
cao ecao[32][32];
void bfsnp(bfnt p) {
for (int i = 0; i < 4; i++) {
int nl = p.f + way[i][0], nr = p.s + way[i][1];
if (nl < 0 || nl >= n || nr < 0 || nr >= m || !ecao[nl][nr].vd)
continue;
int nti = p.ti;
if (ecao[nl][nr].pic >= 0)
nti |= 1 << ecao[nl][nr].pic;
if (!ecao[nl][nr].fnd[nti]) {
ecao[nl][nr].fnd[nti] = true;
tmp.push_back(bfnt{ nl, nr, nti });
if (nti == (1 << picno) - 1) {
res = ans;
bfsn.clear();
tmp.clear();
}
}
}
}
int main() {
cin.sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
char tmp;
cin >> tmp;
if (tmp == '#')
ecao[i][j].vd = false;
else
ecao[i][j].vd = true;
if (tmp == 'p') {
bfsn.push_back(bfnt{ i, j, 0 });
ecao[i][j].fnd[0] = true;
}
if (tmp == '@')
ecao[i][j].pic = picno++;
else
ecao[i][j].pic = -1;
}
while (!bfsn.empty()) {
ans++;
for (int i = 0; i < bfsn.size(); i++) bfsnp(bfsn.at(i));
swap(bfsn, tmp);
tmp.clear();
}
printf("%d", res);
spause();
return 0;
}
10 10
#.########
####.###@#
##########
######.###
@.#.#p#@##
###..##.##
##.#####.#
#.####@#.#
###@##
<15 bytes omitted>
用户输出
-1
系统信息
Exited with return code 0
10 10
.##.@.#.#.
###..##@#.
...#@#.###
.#.#..#...
#..#.....#
....##..##
..##..@.#p
##....##..
..#...
<15 bytes omitted>
用户输出
-1
系统信息
Exited with return code 0
10 10
.#@......#
...#......
..#.....##
..#..#....
...##..@.@
...@#.#...
#.#..#..#.
.p......##
.#..#.
<15 bytes omitted>
用户输出
30
系统信息
Exited with return code 0
20 20
..##.......@........
..#...#....#..##....
...#.#...#..#.#..#..
..#...#..#@###..##..
..#.#....#
<325 bytes omitted>
用户输出
61
系统信息
Exited with return code 0
30 30
##..##.###........#...#...@##.
#.#..#...##.....#.#.#..##p.#.@
...#.##......#...#.#.....#..#@
#
<835 bytes omitted>
用户输出
12
系统信息
Exited with return code 0
30 30
.....#..#...#.@..#..##.#..#...
.#..##.....##..........#.....#
##...##...#.#.......p...#...#.
#
<835 bytes omitted>
用户输出
83
系统信息
Exited with return code 0
30 30
##.....#.......#.....##...#@..
.......#.##.##..#.#.####.##...
.##......#..#.#.......#.....#.
.
<835 bytes omitted>
用户输出
130
系统信息
Exited with return code 0
30 30
...#..###.....##.#....#...##..
#.#...#..#.#..#..#.######..##.
.##..#.@.#......##...#....#.#.
.
<835 bytes omitted>
用户输出
154
系统信息
Exited with return code 0
30 30
..#...#...#...#........#....##
#.##....##.@#.#.#.#.#..@......
#.....#..@....#..#..##.#..#..#
.
<835 bytes omitted>
用户输出
114
系统信息
Exited with return code 0
30 30
#.######.##.####.#######.#####
##.@####.######.#########.##.#
...######.########.########.##
#
<835 bytes omitted>
用户输出
-1
系统信息
Exited with return code 0