编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#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;
}
子任务 #1
Accepted
得分:100
测试点 #1
Accepted
得分:100
用时:5 ms
内存:416 KiB

输入文件(1.in

3 3
p@#
#..
..@

答案文件(1.out

4

用户输出

4

系统信息

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

输入文件(2.in

3 3
p##
@#@
###

答案文件(2.out

-1

用户输出

-1

系统信息

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

输入文件(3.in

5 5
...@.
#####
###.@
#@p#@
..#.#

答案文件(3.out

-1

用户输出

-1

系统信息

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

输入文件(4.in

5 5
.@.@#
#.p..
...##
.@..@
##@#.

答案文件(4.out

12

用户输出

12

系统信息

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

输入文件(5.in

10 10
#.########
####.###@#
##########
######.###
@.#.#p#@##
###..##.##
##.#####.#
#.####@#.#
###@##
<15 bytes omitted>

答案文件(5.out

-1

用户输出

-1

系统信息

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

输入文件(6.in

10 10
.##.@.#.#.
###..##@#.
...#@#.###
.#.#..#...
#..#.....#
....##..##
..##..@.#p
##....##..
..#...
<15 bytes omitted>

答案文件(6.out

-1

用户输出

-1

系统信息

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

输入文件(7.in

10 10
.#@......#
...#......
..#.....##
..#..#....
...##..@.@
...@#.#...
#.#..#..#.
.p......##
.#..#.
<15 bytes omitted>

答案文件(7.out

30

用户输出

30

系统信息

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

输入文件(8.in

20 20
..##.......@........
..#...#....#..##....
...#.#...#..#.#..#..
..#...#..#@###..##..
..#.#....#
<325 bytes omitted>

答案文件(8.out

61

用户输出

61

系统信息

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

输入文件(9.in

30 30
##..##.###........#...#...@##.
#.#..#...##.....#.#.#..##p.#.@
...#.##......#...#.#.....#..#@
#
<835 bytes omitted>

答案文件(9.out

12

用户输出

12

系统信息

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

输入文件(10.in

30 30
.....#..#...#.@..#..##.#..#...
.#..##.....##..........#.....#
##...##...#.#.......p...#...#.
#
<835 bytes omitted>

答案文件(10.out

83

用户输出

83

系统信息

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

输入文件(11.in

30 30
##.....#.......#.....##...#@..
.......#.##.##..#.#.####.##...
.##......#..#.#.......#.....#.
.
<835 bytes omitted>

答案文件(11.out

130

用户输出

130

系统信息

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

输入文件(12.in

30 30
...#..###.....##.#....#...##..
#.#...#..#.#..#..#.######..##.
.##..#.@.#......##...#....#.#.
.
<835 bytes omitted>

答案文件(12.out

154

用户输出

154

系统信息

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

输入文件(13.in

30 30
..#...#...#...#........#....##
#.##....##.@#.#.#.#.#..@......
#.....#..@....#..#..##.#..#..#
.
<835 bytes omitted>

答案文件(13.out

114

用户输出

114

系统信息

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

输入文件(14.in

30 30
#.######.##.####.#######.#####
##.@####.######.#########.##.#
...######.########.########.##
#
<835 bytes omitted>

答案文件(14.out

-1

用户输出

-1

系统信息

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

输入文件(15.in

30 30
########.###.###.###.###.##.##
######.####..#.###.###########
########.####.#########.######
.
<835 bytes omitted>

答案文件(15.out

11

用户输出

11

系统信息

Exited with return code 0