QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#188596#5489. Room EvacuationGamal74AC ✓1625ms55180kbC++203.4kb2023-09-26 03:29:252023-09-26 03:29:25

Judging History

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

  • [2023-09-26 03:29:25]
  • 评测
  • 测评结果:AC
  • 用时:1625ms
  • 内存:55180kb
  • [2023-09-26 03:29:25]
  • 提交

answer

#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")

#include "bits/stdc++.h"

using namespace std;

#define pb push_back
#define F first
#define S second
#define f(i, a, b)  for(int i = a; i < b; i++)
#define all(a)  a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define mp(x, y) make_pair(x,y)
#define popCnt(x) (__builtin_popcountll(x))
#define int ll

using ll = long long;
using ii = pair<int, int>;
using ull = unsigned long long;

const int N = 5e5 + 5, LG = 18, MOD = 1e9 + 7;
const long double PI = acos(-1);
const long double EPS = 1e-7;

#define rep(aa, bb, cc) for(int aa = bb; aa < cc;aa++)
struct Dinic {
	struct Edge {
		int to, rev;
		ll c, oc;
		ll flow() { return max(oc - c, 0LL); } // if you need flows
	};
	vector<int> lvl, ptr, q;
	vector<vector<Edge>> adj;
	Dinic(int n) : lvl(n), ptr(n), q(n), adj(n) {}
	void addEdge(int a, int b, ll c, ll rcap = 0) {
		adj[a].push_back({b, (int)adj[b].size(), c, c});
		adj[b].push_back({a, (int)adj[a].size() - 1, rcap, rcap});
	}
	ll dfs(int v, int t, ll f) {
		if (v == t || !f) return f;
		for (int& i = ptr[v]; i < (int)adj[v].size(); i++) {
			Edge& e = adj[v][i];
			if (lvl[e.to] == lvl[v] + 1)
				if (ll p = dfs(e.to, t, min(f, e.c))) {
					e.c -= p, adj[e.to][e.rev].c += p;
					return p;
				}
		}
		return 0;
	}
	ll calc(int s, int t) {
		ll flow = 0; q[0] = s;
		rep(L,0,31) do { // 'int L=30' maybe faster for random data
			lvl = ptr = vector<int>((int)q.size());
			int qi = 0, qe = lvl[s] = 1;
			while (qi < qe && !lvl[t]) {
				int v = q[qi++];
				for (Edge e : adj[v])
					if (!lvl[e.to] && e.c >> (30 - L))
						q[qe++] = e.to, lvl[e.to] = lvl[v] + 1;
			}
			while (ll p = dfs(s, t, LLONG_MAX)) flow += p;
		} while (lvl[t]);
		return flow;
	}
	bool leftOfMinCut(int a) { return lvl[a] != 0; }
};

int n, m, t;
char grid[22][22];
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};

int getId(int i, int j, int t, bool o) {
    int val = n * m * t;
    val += i * m + j;
    return val * 2 + o;
}

void doWork() {
    cin >> n >> m >> t;
    f(i, 0, n)f(j, 0, m) cin >> grid[i][j];
    Dinic flw(n * m * (t + 1) * 2 + 2);
    int src = n * m * (t + 1) * 2;
    int snk = n * m * (t + 1) * 2 + 1;
    f(i, 0, n)f(j, 0, m) if (grid[i][j] != '#') {
                if (grid[i][j] == 'P')flw.addEdge(src, getId(i, j, 0, 0), 1);
                if (grid[i][j] == 'E') {
                    f(x, 0, t + 1)flw.addEdge(getId(i, j, x, 1), snk, 1);
                }
                f(x, 0, t + 1)flw.addEdge(getId(i, j, x, 0), getId(i, j, x, 1), 1);
                f(x, 0, t)flw.addEdge(getId(i, j, x, 1), getId(i, j, x + 1, 0), 1);
                f(k, 0, 4) {
                    int ni = i + dx[k];
                    int nj = j + dy[k];
                    if (ni >= 0 && nj >= 0 && ni < n && nj < m && grid[ni][nj] != '#') {
                        f(x, 0, t) {
                            flw.addEdge(getId(i, j, x, 1), getId(ni, nj, x + 1, 0), 1);
                        }
                    }
                }
            }

    cout << flw.calc(src, snk) << '\n';

}

int32_t main() {
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif // ONLINE_JUDGE

    int t = 1;
//    cin >> t;
    while (t--) {
        doWork();
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3596kb

input:

4 5 3
.....
..P#.
..PPE
..P.E

output:

4

result:

ok single line: '4'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3784kb

input:

3 3 5
...
P#P
P#E

output:

2

result:

ok single line: '2'

Test #3:

score: 0
Accepted
time: 7ms
memory: 11184kb

input:

20 15 53
PPEP..PP#P.#P.#
P.###EP#PEPP.E#
.PEEPEEP#E#PPE#
PE#.##P#..PP.##
E.PPP.#E##EPE##
E#P#.EEE.EEPPPP
P.#PPPE.PPPP#.P
.##EEEE.#E.E.##
P..P#PEPPEE#.PP
EPEEEEE#E.E.E#P
##.E.EPP.PEE.EP
..E#.PE.#EP.#PE
EEEEPP.E.#.EEP.
..E#PPE.#EPEP..
EPP.#.PP#P#P#PE
EE#.PP.#EP.PPE#
EEPP####P#.#E.#
PP.EEE..###PEP.
#EP...

output:

89

result:

ok single line: '89'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3924kb

input:

4 1 137
.
#
#
#

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 16ms
memory: 22388kb

input:

14 15 200
###EPP...#P.E#.
#.##EE#E#.PP#EP
E.PPP.E.#.##PPP
#E.EP##..#.#.##
#P###EEE#E#.E.#
#P..EPPE.#..EE.
PP#P#E.#PP#.PEE
.PEPEE#E#..EE##
EE.PP.PE#EE#PEE
P.#EPP.P#.EPP#P
E..#P#PEPE#EP.#
E.PP.EEP.#.#...
PP.P#P#PEEEPPEE
#.EE.P.P.P#E#PP

output:

55

result:

ok single line: '55'

Test #6:

score: 0
Accepted
time: 11ms
memory: 14932kb

input:

9 13 200
.P.E.PEPP.EE.
.##E.EEE.P##.
P##P.#..EP.PE
E#EE...PEEP.E
E#....PPP#PPP
.#EPE.PPEP#PE
#EEP...##P...
#.P##EE#.E#.#
#EPEP.E...P#P

output:

28

result:

ok single line: '28'

Test #7:

score: 0
Accepted
time: 2ms
memory: 4976kb

input:

8 13 28
#PEPP..#E##EE
EEEPPEPPE...E
..##PP#P#..#P
P...PP.PPE#PE
EPPEE.PEEPEPP
#EPE#PE#####.
P.P#.#E.E...P
###EP##.EP.PP

output:

32

result:

ok single line: '32'

Test #8:

score: 0
Accepted
time: 12ms
memory: 25680kb

input:

13 20 200
P.E#E.P.#EP#P..#.#E.
..E...P.E#EP#.PE.P#P
##E#E#.P##P#PP#E#.EE
.P#..#PP.E#E#E#E#PPP
#P.EEP..EPEPPEE..E#E
PPE###...EEPP#.#E.P.
PP.#.##E#E##.P#.EPEE
EE#PEPE.#P#.PP..EP..
#.EPE#P.P#EEPPP.P##.
####E###PE#E###EPP##
#.EP#.#..#.#E#..#EPE
E#EEPE#PP..EPE#P#P.E
.#PPE#E.#.#EP#PEE#EP

output:

62

result:

ok single line: '62'

Test #9:

score: 0
Accepted
time: 3ms
memory: 10572kb

input:

14 5 200
..EEP
P.EE#
P.###
##.P#
#E.EP
...EE
..#..
PEPEE
##.PP
.P..P
PP#..
E.#EP
E..P.
EE.E.

output:

15

result:

ok single line: '15'

Test #10:

score: 0
Accepted
time: 0ms
memory: 3764kb

input:

2 1 167
P
P

output:

0

result:

ok single line: '0'

Test #11:

score: 0
Accepted
time: 4ms
memory: 15352kb

input:

6 20 199
.PE.E...P.EE...PE.##
P.EPP.#EE#E.PP.P.#.E
E#E#E#EEP.P.E##P.E##
EEP#PPE#EE..##PPPP.#
.PE#EP.PE#EE.P.E#EE#
E#P.EEPP..P..EE#E#.P

output:

28

result:

ok single line: '28'

Test #12:

score: 0
Accepted
time: 4ms
memory: 12216kb

input:

7 14 200
#PE##..E#EPEP.
###PEPE.P##PPP
#E.#P#PE###.PP
.E#E.#EEE#PP.P
P..EEEE#.E#P..
#.E.P.PEPEPP#.
#E#EEPE.E##...

output:

24

result:

ok single line: '24'

Test #13:

score: 0
Accepted
time: 13ms
memory: 16352kb

input:

8 19 200
.#..#P#.P.P#.E.E..P
#P.P##..P.PPE.EEP.E
#.##P.#E.P##P....E.
##EPEE#.EPP.#.#EE.#
#.#EPP#EE.PP#E#E.##
PPPPE.EEP#EPEE..PPP
#P###PPP#EP..E#P###
#.##EPPE.#.PE#E.##P

output:

35

result:

ok single line: '35'

Test #14:

score: 0
Accepted
time: 7ms
memory: 11352kb

input:

6 15 200
##.#P.E#.PE.P.E
PEE...#E#EE..#P
P.#.E#EP..#E...
.EE#P#E.P.PEP#P
P###.EE#P##.EEE
.PE.E.P.PP.###.

output:

18

result:

ok single line: '18'

Test #15:

score: 0
Accepted
time: 0ms
memory: 5184kb

input:

2 12 200
#P.E.#...P#E
E.##..#.P#..

output:

1

result:

ok single line: '1'

Test #16:

score: 0
Accepted
time: 1ms
memory: 3888kb

input:

12 1 108
#
#
E
P
#
.
P
#
E
#
#
.

output:

1

result:

ok single line: '1'

Test #17:

score: 0
Accepted
time: 8ms
memory: 19396kb

input:

17 15 126
#.##.EEPEP#EE.E
#P.#PPEP.P.#E#P
.P##E.##E.E##PE
P#EPPE.E#.#EPE#
.EEEE.P#E.P...#
P.PEPPEEEE.PE#.
.#E..#...PPPPEP
##.EE.PE.PPPPE.
P..P#PEP....P#E
P.#...P...EPEE.
#EE#.EPP#PEE.##
.#.##.P#PEE###E
#.#..#..EE.E#.P
.#.#E.PPEEE...P
PPPP##.E.PPEEPP
EE.EE.EP.PEPPP.
EP#P.P.P.#.P.P.

output:

67

result:

ok single line: '67'

Test #18:

score: 0
Accepted
time: 1625ms
memory: 55180kb

input:

20 20 200
PPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPP...

output:

200

result:

ok single line: '200'

Test #19:

score: 0
Accepted
time: 75ms
memory: 54808kb

input:

20 20 200
E#PPPPPPPPPPPPPPPPPP
##PPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPP...

output:

0

result:

ok single line: '0'

Test #20:

score: 0
Accepted
time: 3ms
memory: 13084kb

input:

20 20 38
E...................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
.....................

output:

1

result:

ok single line: '1'

Test #21:

score: 0
Accepted
time: 7ms
memory: 13008kb

input:

20 20 37
E...................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
.....................

output:

0

result:

ok single line: '0'

Test #22:

score: 0
Accepted
time: 2ms
memory: 4996kb

input:

20 20 5
.....EEEEEEEEEE.....
PPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPPPP
....................
....................
....................
....................
....................
....................
....................
......................

output:

50

result:

ok single line: '50'

Test #23:

score: 0
Accepted
time: 412ms
memory: 23840kb

input:

20 20 200
P#PPP#PPP#PPP#PPP#E#
P#P#P#P#P#P#P#P#P#P#
P#P#P#P#P#P#P#P#P#P#
P#P#P#P#P#P#P#P#P#P#
P#P#P#P#P#P#P#P#P#P#
P#P#P#P#P#P#P#P#P#P#
P#P#P#P#P#P#P#P#P#P#
P#P#P#P#P#P#P#P#P#P#
P#P#P#P#P#P#P#P#P#P#
P#P#P#P#P#P#P#P#P#P#
P#P#P#P#P#P#P#P#P#P#
P#P#P#P#P#P#P#P#P#P#
P#P#P#P#P#P#P#P#P#P#
P#P#P#P#P#P#P#P#P...

output:

200

result:

ok single line: '200'

Test #24:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

3 5 2
P.E.P
.....
..P..

output:

1

result:

ok single line: '1'

Test #25:

score: 0
Accepted
time: 1ms
memory: 3752kb

input:

1 20 19
P..................E

output:

1

result:

ok single line: '1'

Test #26:

score: 0
Accepted
time: 1ms
memory: 3760kb

input:

6 9 6
..E...E..
.........
##.###.##
#P...P.P#
#.P...PP#
#########

output:

6

result:

ok single line: '6'

Test #27:

score: 0
Accepted
time: 1ms
memory: 3760kb

input:

6 9 6
..E...E..
.........
##.###.##
#P.P...P#
#PP...P.#
#########

output:

6

result:

ok single line: '6'

Test #28:

score: 0
Accepted
time: 1ms
memory: 3952kb

input:

9 6 6
####..
#.P#..
#P...E
#..#..
#..#..
#.P#..
#P...E
#PP#..
####..

output:

6

result:

ok single line: '6'

Test #29:

score: 0
Accepted
time: 1ms
memory: 3700kb

input:

9 6 6
####..
#PP#..
#P...E
#.P#..
#..#..
#..#..
#P...E
#.P#..
####..

output:

6

result:

ok single line: '6'

Test #30:

score: 0
Accepted
time: 1ms
memory: 3700kb

input:

6 9 6
#########
#PP...P.#
#P.P...P#
##.###.##
.........
..E...E..

output:

6

result:

ok single line: '6'

Test #31:

score: 0
Accepted
time: 1ms
memory: 3976kb

input:

6 9 6
#########
#.P...PP#
#P...P.P#
##.###.##
.........
..E...E..

output:

6

result:

ok single line: '6'

Test #32:

score: 0
Accepted
time: 1ms
memory: 3760kb

input:

9 6 6
..####
..#PP#
E...P#
..#P.#
..#..#
..#..#
E...P#
..#P.#
..####

output:

6

result:

ok single line: '6'

Test #33:

score: 0
Accepted
time: 0ms
memory: 3944kb

input:

9 6 6
..####
..#P.#
E...P#
..#..#
..#..#
..#P.#
E...P#
..#PP#
..####

output:

6

result:

ok single line: '6'

Test #34:

score: 0
Accepted
time: 26ms
memory: 23900kb

input:

20 20 200
P#...#...#...#...#E#
.#.#.#.#.#.#.#.#.#.#
.#.#.#.#.#.#.#.#.#.#
.#.#.#.#.#.#.#.#.#.#
.#.#.#.#.#.#.#.#.#.#
.#.#.#.#.#.#.#.#.#.#
.#.#.#.#.#.#.#.#.#.#
.#.#.#.#.#.#.#.#.#.#
.#.#.#.#.#.#.#.#.#.#
.#.#.#.#.#.#.#.#.#.#
.#.#.#.#.#.#.#.#.#.#
.#.#.#.#.#.#.#.#.#.#
.#.#.#.#.#.#.#.#.#.#
.#.#.#.#.#.#.#.#....

output:

0

result:

ok single line: '0'

Test #35:

score: 0
Accepted
time: 69ms
memory: 55104kb

input:

20 20 200
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................

output:

0

result:

ok single line: '0'

Test #36:

score: 0
Accepted
time: 3ms
memory: 6232kb

input:

20 20 14
..###P#.EP......#...
P#P.#.P.#......E.#P.
.##P#......#.#.#....
..PP#P...#....##....
P..P..PP..EE.#..#.#.
#P#....PPP#P.P..E##.
.###PPP.#.E.P.E.PP..
#PP.PP...EPP##PP.P..
..##.P..#P##.E.##P#E
E.....P...#P.#.#..#.
....#.#..#..EP.#.P..
....EPEE#.....E.....
.P..#..P.E...P.PEP#.
P..EP.##E...#.P.##...

output:

75

result:

ok single line: '75'

Test #37:

score: 0
Accepted
time: 3ms
memory: 7976kb

input:

20 20 23
...P..PEPPPP.PPEP.P#
E..P.##.E.P##EPPP.P.
E.P..EP.P.#P..P#P.#P
.E.P....###EP.#PPPEP
EE#P.P.P.PPP.#..P#PP
EP..##PP...PP.P..P.E
#E.E.#P.#.#..E#..PPP
EP#PPE##.P.PE.PPP.P.
P.PEPP.#...P#P.PPP.E
.#P.E.PP.PP...P.P.P.
#...#P#P##P#E#P.#...
#P#PP.PP#..PEPP.#PPP
P#.P.P##PP.#.P##P#P#
..#.#E.#E....PP......

output:

148

result:

ok single line: '148'

Test #38:

score: 0
Accepted
time: 3ms
memory: 5544kb

input:

20 20 10
#.P.....##....#.PPP.
#..PP...PP.#........
#..#.......#..#...##
.PE..P..........#..#
P##P....E.....E#....
P............#..#...
.E#..............P..
..........#..P....#.
###.E#.##P..#....E#P
E.#.#...#.##..E..P..
P#............P..#.#
.PPP###...P.........
..#...P.....#...#.#.
...#.E..P..#P##..#...

output:

38

result:

ok single line: '38'

Test #39:

score: 0
Accepted
time: 3ms
memory: 5576kb

input:

20 20 10
E..P...E..P.#.P....#
.........#.......#.E
E......EP..#........
.P...#.#.#.PP.....E.
........P#.......##.
..#.##.#.P#...E#P###
....#..#.P#E...PP##.
....P#...E......#..#
.#.P......#P.E......
....E.......E......P
.#.E...........#P#E#
......#...PP.....##.
..#......#...E##.#..
..E...#...#......P...

output:

36

result:

ok single line: '36'

Test #40:

score: 0
Accepted
time: 3ms
memory: 5568kb

input:

20 20 10
..E...P##.P#.E....#.
.P...E#....P......#.
P.#.#..#.....E...E..
.##......P.E........
#..P#.P..#.P...E.P..
...P..........#..#..
.E...E.........P#.P#
....#..............#
.#....E..#....#.P.#.
..#....P..#.....P...
...E...#E...#.#.....
#...P.#..#......####
.#..P....P.P#...PP#E
..#......P#P...P.....

output:

33

result:

ok single line: '33'

Test #41:

score: 0
Accepted
time: 3ms
memory: 5592kb

input:

20 20 10
....P.E.....#P......
.....E###.P.#P..#...
.#.P.P..P....P...##P
..........P#E#..#..#
#...E..#..........EP
.E.P..#P...P#...E.#.
........#.#.P...PEE.
.....P.....##..#E...
....P.....PE#....P#E
.P.##..E.........#.P
.#.....#E....#...#.P
#..#..PE.#..P..#...#
.....P....#.##..PP..
.................#...

output:

39

result:

ok single line: '39'

Test #42:

score: 0
Accepted
time: 3ms
memory: 5532kb

input:

20 20 10
....#...P##.......P.
..P#E.#.P#.E....#...
....#..PPP.........#
....E#..P#....P#....
...........#..##.#..
.....P........E#P...
.........#P..E......
..###.#.P##.....E#.#
.#..P#......PE#....#
#...##........#...#E
.##.#..#P#..#.E..#.P
E.#........#...P....
..E##EP....PP#PP...#
....#..##P...#P..P...

output:

33

result:

ok single line: '33'

Test #43:

score: 0
Accepted
time: 0ms
memory: 3696kb

input:

1 1 200
E

output:

0

result:

ok single line: '0'

Test #44:

score: 0
Accepted
time: 1ms
memory: 3932kb

input:

1 1 200
P

output:

0

result:

ok single line: '0'

Test #45:

score: 0
Accepted
time: 0ms
memory: 3832kb

input:

1 1 200
.

output:

0

result:

ok single line: '0'

Test #46:

score: 0
Accepted
time: 0ms
memory: 3820kb

input:

1 1 200
#

output:

0

result:

ok single line: '0'

Test #47:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

1 2 1
PE

output:

1

result:

ok single line: '1'

Test #48:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

1 3 1
P.E

output:

0

result:

ok single line: '0'

Test #49:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

20 1 19
P
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
E

output:

1

result:

ok single line: '1'