QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#656438 | #9224. Express Eviction | yanchengzhi | WA | 1ms | 3848kb | C++20 | 1.7kb | 2024-10-19 12:58:59 | 2024-10-19 12:59:00 |
Judging History
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: 3848kb
input:
4 6 .##... .#.... ##.... ....#.
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3592kb
input:
20 30 ...########################### #..########################### ...########################### ...########################### .############################# ...########################### ...########################### #..########################### ...########################### ..#...............
output:
5
result:
wrong answer 1st numbers differ - expected: '11', found: '5'