QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#656430#9224. Express Evictionwoodie_0064#WA 0ms3700kbC++201.7kb2024-10-19 12:57:282024-10-19 12:57:29

Judging History

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

  • [2024-10-19 12:57:29]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3700kb
  • [2024-10-19 12:57:28]
  • 提交

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][5];

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,4>> q;
	memset(dis,inf,sizeof dis);
	for(int i = 0;i < 2;i++) {
		dis[1][1][i] = 0;
		q.push({0,1,1,i});
	}
	auto valid = [&] (int x,int y) {
		return x >= 1 && x <= n + 1 && y >= 1 && y <= m + 1;
	};
	
	while(!q.empty()) {
		auto [d,x,y,from] = q.top();
		q.pop();
		d = -d;
//		cout << x << ' ' << y << ' ' << from << ' ' << d << '\n';
		if(dis[x][y][from] < 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);
//			cout << xx << ' ' << yy << '\n';
			if(i % 2) {
				if(s[nowx][nowy - 1] == '#') {
					cost += 1;
					if(from == 1) cost -= 1;
				}
				if(s[nowx][nowy] == '#') {
					cost += 1;
					if(from == 3) cost -= 1;
				}
			}else {
				if(s[nowx - 1][nowy] == '#') {
					cost += 1;
					if(from == 0) cost -= 1;
				}
				if(s[nowx][nowy + 1] == '#') {
					cost += 1;
					if(from == 2) cost -= 1;
				}
			}
			if(d + cost < dis[xx][yy][i]) {
				dis[xx][yy][i] = d + cost;
				q.push({-dis[xx][yy][i],xx,yy,i});
			}
		}
	}
}


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: 0ms
memory: 3644kb

input:

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

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

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

output:

5

result:

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