QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#563903#9224. Express EvictionWRuperDRE 4ms4928kbC++202.7kb2024-09-14 17:02:242024-09-14 17:02:24

Judging History

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

  • [2024-09-14 17:02:24]
  • 评测
  • 测评结果:RE
  • 用时:4ms
  • 内存:4928kb
  • [2024-09-14 17:02:24]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const int mininf = 1e9 + 7;
#define int long long
#define pb emplace_back
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
inline void write(int x){if(x<0){x=~(x-1);putchar('-');}if(x>9)write(x/10);putchar(x%10+'0');}
#define put() putchar(' ')
#define endl puts("")
const int MAX = 3e3 + 10;
int psz = 2;

struct flow{
	struct node{
		int v, w, cp;
	}; vector <node> g[MAX];
	
	int dis[MAX];
	
	bool bfs(int s, int t){
		for(int i = 1; i <= psz; i++)	dis[i] = mininf;
		dis[s] = 0;
		queue <int> q;
		q.push(s);
		while(!q.empty()){
			int u = q.front();
			q.pop();
			for(auto V : g[u]){
				if(V.w > 0 and dis[V.v] > dis[u] + 1){
					dis[V.v] = dis[u] + 1;
					q.push(V.v);
				}
			}
		}
		if(dis[t] == mininf)	return 0;
		return 1;
	}
	
	int cur[MAX];
	
	int aug(int u, int now, int t){
		if(u == t)	return now;
		int ans = 0;
		for(int &i = cur[u]; i < g[u].size(); i++){
			int v = g[u][i].v, w = g[u][i].w, cp = g[u][i].cp;
			if(dis[v] != dis[u] + 1)	continue;
			int ret = aug(v, min(w, now), t);
			g[u][i].w -= ret, g[v][cp].w += ret;
			now -= ret, ans += ret;
			if(now <= 0)	break;
		}
		return ans;
	}
	
	void add_edge(int u, int v, int w){
		g[u].pb(node{v, w, g[v].size()});
		g[v].pb(node{u, 0, g[u].size() - 1});
	}
}; flow G;
      
int id[55][55][2];

int a[55][55];


void solve(){
	int n = read(), m = read();
	int s = 1, t = 2;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			char ch = getchar();
			while(ch != '.' and ch != '#'){
				ch = getchar();
			}
			if(ch == '#'){
				a[i][j] = 1;
				id[i][j][0] = ++psz, id[i][j][1] = ++psz;
			}
		}
	}
	for(int i = 1; i <= m; i++)	if(a[1][i])	G.add_edge(id[1][i][1], t, inf);
	for(int i = 1; i <= n; i++)	if(a[i][1])	G.add_edge(s, id[i][1][0], inf);
	for(int i = 1; i <= m; i++)	if(a[n][i])	G.add_edge(s, id[n][i][0], inf);
	for(int i = 1; i <= n; i++)	if(a[i][m])	G.add_edge(id[i][m][1], t, inf);
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(!a[i][j])	continue;
			G.add_edge(id[i][j][0], id[i][j][1], 1);
			for(int k = max(1ll, i - 2); k <= min(n, i + 2); k++){
				for(int k2 = max(1ll, j - 2); k2 <= min(m, j + 2); k2++){
					if(k == i and k2 == j)	continue;
					if(a[k][k2]){
						G.add_edge(id[i][j][1], id[k][k2][0], inf);
					}
				}
			}
		}
	}
	int ans = 0;
	while(G.bfs(s, t)){
		for(int i = 1; i <= psz; i++)	G.cur[i] = 0;
		ans += G.aug(s, inf, t);
	}
	write(ans), endl;
}

signed main(){
	int t = 1;
	while(t--)	solve();
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3660kb

input:

4 6
.##...
.#....
##....
....#.

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

20 30
...###########################
#..###########################
...###########################
...###########################
.#############################
...###########################
...###########################
#..###########################
...###########################
..#...............

output:

11

result:

ok 1 number(s): "11"

Test #3:

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

input:

35 35
....###########...#########........
##..#######################..#####.
....#######################..#####.
...#.....##################..#####.
.##......##################.....##.
.##..##..#############.....#....##.
.....##..#############......##..##.
....#....#############..##..##..##.
####.....

output:

16

result:

ok 1 number(s): "16"

Test #4:

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

input:

30 20
.#..........##......
..#......#..##......
.......#..........#.
..#......#..##......
.....#......#.......
.#.........#........
......#...#.........
..#..##..#...#......
......#.......#.....
..#....#............
........#..#.#......
....##..#...........
.........#.#.......#
........##..........
...

output:

5

result:

ok 1 number(s): "5"

Test #5:

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

input:

50 45
...##................##...................#..
...#......#.#..........#.#.....####....#....#
....#.....#..............#..#..##......##..#.
.....#......######........#.............#....
......##...#...##...##.......#....#..#...##..
...#..##.....##...###.............#..##.....#
...#......########...

output:

24

result:

ok 1 number(s): "24"

Test #6:

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

input:

50 45
...#...................#.####................
...........................#......###.#..##..
..#.#........##.##....#....#.................
.....#.....#.##.#.#.........#................
...........#.#.#.#.##....#.#.......##.#..#...
...#......#...#####......#...##.##........#..
............####.....

output:

23

result:

ok 1 number(s): "23"

Test #7:

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

input:

50 50
##................................................
#################################################.
####..............................................
####..............................................
####..############################################
####......................................

output:

7

result:

ok 1 number(s): "7"

Test #8:

score: -100
Runtime Error

input:

50 50
#.##.##..###...#######.##..#####.#...######.######
.####.##.##.#############.#.#.###.##.###.#.#.###.#
...####.##########.###.####.#.####.#############..
#.#..########.#.#####.#..#.##....##########.#.####
###.##.####.###.#######..##.#####...##.#######..#.
#####.########..########..#######.##.#....

output:


result: