QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#644833#9224. Express Evictionucup-team2432#WA 1ms3700kbC++172.2kb2024-10-16 15:34:332024-10-16 15:34:33

Judging History

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

  • [2024-10-16 15:34:33]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3700kb
  • [2024-10-16 15:34:33]
  • 提交

answer

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define ll long long
#define all(v) v.begin(),v.end()
#define sz(v) ((ll)v.size())
#define V vector
#define vi V<int>
#define vll V<ll>
#define eb emplace_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define A array
#define pb push_back
#define mset multiset
#define gpumap __gnu_pbds::gp_hash_table
#define ccumap __gnu_pbds::cc_hash_table
#define ui unsigned int
#define ull unsigned ll
#define i128 __int128
#define cerr if (test) cerr
#define freopen if (test) freopen
#define whtest if (test)
using namespace std;

constexpr int test = 0;

namespace jhsy {
	void main() {
		int n,m;
		cin >> n >> m;
		n += 2; m += 2;
		V<string> s(n);
		V a(n,vi(m));
		s[0] = s.back() = string(m,'.');
		for (int i = 1; i+1 < sz(s); i++) {
			cin >> s[i]; s[i] = '.'+s[i]+'.';
			for (int j = 0; j < m; j++) {
				a[i][j] = s[i][j] == '#';
			}
		}
		V id(n-1,vi(m-1));
		int cnt = 0;
		for (int i = 0; i < n-1; i++) {
			for (int j = 0; j < m-1; j++) {
				id[i][j] = cnt++;
			}
		}
		constexpr int inf = 1e9;
		V e(cnt,V<pii>{});
		for (int i = 0; i < n-1; i++) {
			for (int j = 0; j+1 < m-1; j++) {
				e[id[i][j]].eb(id[i][j+1],a[i][j+2]+a[i+1][j+2]);
				e[id[i][j+1]].eb(id[i][j],a[i][j]+a[i+1][j]);
			}
		}
		for (int i = 0; i+1 < n-1; i++) {
			for (int j = 0; j < m-1; j++) {
				e[id[i][j]].eb(id[i+1][j],a[i+2][j]+a[i+2][j+1]);
				e[id[i+1][j]].eb(id[i][j],a[i][j]+a[i][j+1]);
			}
		}
		V dis(cnt,inf);
		priority_queue<pii,V<pii>,greater<>> q;
		dis[id[0][0]] = a[0][0]+a[0][1]+a[1][0]+a[1][1];
		q.emplace(dis[id[0][0]],id[0][0]);
		while (!q.empty()) {
			auto [d,u] = q.top(); q.pop();
			if (d == dis[u]) {
				for (auto [v,w]:e[u]) {
					if (dis[v] > d+w) {
						q.emplace(dis[v] = d+w,v);
					}
				}
			}
		}
		cout << dis[id[n-1-1][m-1-1]] << '\n';
	}
}

int main() {
	freopen("test.in","r",stdin);
	freopen("test.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(20);

//	jhsy::init();

	int T = 1;
//	cin >> T;
	while (T--) {
		jhsy::main();
	}

	return 0;
}

詳細信息

Test #1:

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

input:

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

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3700kb

input:

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

output:

12

result:

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