QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#656524#9224. Express Evictionwoodie_0064#WA 1ms3644kbC++201.6kb2024-10-19 13:15:532024-10-19 13:15:55

Judging History

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

  • [2024-10-19 13:15:55]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3644kb
  • [2024-10-19 13:15:53]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 3;
int T;
int n, num;
const int inf = 0x3f3f3f3f;
const int dx[] = {1,0,-1,0};
const int dy[] = {0,1,0,-1};
int dis[55][55];

void work(){
	int n,m;cin >> n >> m;
	vector <string> s(n + 2);
	s[0] = s[n + 1] = string(m + 2,'.');
	for(int i = 1;i <= n;i++) {
		string str;cin >> str;
		s[i] = "." + str + ".";
	}
	priority_queue <array <int,3>> q;
	memset(dis,inf,sizeof dis);
	if(s[1][1] == '#') dis[1][1] = 1;
	else dis[1][1] = 0;
	q.push({-dis[1][1],1,1});
	auto valid = [&] (int x,int y) {
		return x >= 1 && x <= n + 1 && y >= 1 && y <= m + 1;
	};
	
	while(!q.empty()) {
		auto [d,x,y] = q.top();
		q.pop();
		d = -d;
//		cout << x << ' ' << y << ' ' << from << ' ' << d << '\n';
		if(dis[x][y] < d) continue;
		if(x == n + 1 && y == m + 1) {
			cout << d << '\n';
			break;
		}
		for(int i = 0;i < 4;i++) {
			int xx = x + dx[i],yy = y + dy[i];
			if(!valid(xx,yy)) continue;
			int cost = 0;
			int nowx = min(x,xx),nowy = min(y,yy);
			if(i == 0 || i == 2) {
				if(i == 2) nowx -= 1;
				else if(i == 0) nowx += 1;
				if(s[nowx][nowy] == '#') cost += 1;
				if(s[nowx][nowy - 1] == '#') cost += 1;
			}else {
				if(i == 3) nowy -= 1;
				else nowy += 1;
				if(s[nowx][nowy] == '#') cost += 1;
				if(s[nowx - 1][nowy] == '#') cost += 1;
			}
			if(d + cost < dis[xx][yy]) {
				dis[xx][yy] = d + cost;
				q.push({-dis[xx][yy],xx,yy});
			}
		}
	}
}


int main(){
//	freopen("test.txt", "r", stdin);
	ios::sync_with_stdio(false);
	cin.tie(0);
//	cin >> T;
//	while(T--){
		work();
//	}	
	return 0;
}

详细

Test #1:

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

input:

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

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

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

output:

12

result:

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