QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#673444#9224. Express Evictionucup-team191#WA 0ms4500kbC++232.5kb2024-10-24 22:25:282024-10-24 22:25:29

Judging History

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

  • [2024-10-24 22:25:29]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4500kb
  • [2024-10-24 22:25:28]
  • 提交

answer

#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <algorithm>

#define PB push_back
#define sz(x) ((int)(x).size())

using namespace std;


typedef pair < int, int > pii;
typedef vector < int > vi;

const int N = 54;
const int M = 1e5 + 500;

int A[N][N];

/**

const ll INF = (1LL << 60);
struct Dinic {
	struct Edge {
		int to, rev;
		ll c, oc;
		ll flow() { return max(oc - c, 0LL); }
	};
	vi 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, sz(adj[b]), c, c});
		adj[b].push_back({a, sz(adj[a]) - 1, rcap, rcap});
	}
	ll dfs(int v, int t, ll f) {
		if(v == t || !f) return f;
		for(int &i = ptr[v]; i < sz(adj[v]);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;
		for(int L = 0;L < 31;L++) do {
			lvl = ptr = vi(sz(q));
			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, INF)) flow += p;
			}		
		} while(lvl[t]);
		return flow;
	}
};

**/

int n, m;
char s[N][N];
vector < pii > v[M];
int dis[M];

int get(int A, int B) {
	if(A < 0 || A >= n) return 0;
	if(B < 0 || B >= m) return 0;
	return s[A][B] == '#';
}

int code(int A, int B) {
	return A * (m + 1) + B;
}

int main() {
	scanf("%d%d", &n, &m);
	for(int i = 0;i < n;i++) scanf("%s", s[i]);
	for(int i = 0;i <= n;i++) {
		for(int j = 0;j <= m;j++) {
			if(i + 1 <= n) {
				v[code(i, j)].PB({code(i + 1, j), get(i + 1, j - 1) + get(i + 1, j)});
				v[code(i + 1, j)].PB({code(i, j), get(i - 1, j - 1) + get(i - 1, j)});
			}
			if(j + 1 <= m) {
				v[code(i, j)].PB({code(i, j + 1), get(i - 1, j + 1) + get(i, j + 1)});
				v[code(i, j + 1)].PB({code(i, j), get(i - 1, j - 1) + get(i, j - 1)});
			}
		}
	}
	memset(dis, -1, sizeof(dis));
	dis[0] = get(0, 0);
	set < pii > S;
	S.insert({0, 0});
	for(;!S.empty();) {
		int cur = S.begin()->second;
		S.erase(S.begin());
		for(auto &[nxt, weight] : v[cur]) {
			if(dis[nxt] == -1 || weight + dis[cur] < dis[nxt]) {
				dis[nxt] = dis[cur] + weight;
				S.insert({dis[nxt], nxt});
			}
		}
	}
	printf("%d\n", dis[code(n, m)]);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 4500kb

input:

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

output:

12

result:

wrong answer 1st numbers differ - expected: '11', found: '12'