QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#539882 | #9224. Express Eviction | Chinese_zjc_# | WA | 1ms | 3788kb | C++20 | 2.0kb | 2024-08-31 15:56:42 | 2024-08-31 15:56:42 |
Judging History
answer
#include<bits/stdc++.h>
int n,m,h[55][55],s[55][55],cnt,dis[5005];
bool a[55][55];
char c;
std::vector<std::pair<int,int> > e[5005];
void add(int A,int B,int C)
{
if(1<=A&&A<=cnt&&1<=B&&B<=cnt)
e[A].push_back({B,C});
}
signed main()
{
std::ios::sync_with_stdio(false);
std::cin>>n>>m;
for(int i=1;i<=n;++i)
for(int j=1;j<=m;++j)
std::cin>>c,a[i][j]=c=='#';
for(int i=0;i<=n;++i)
{
for(int j=1;j<=m;++j)
{
h[i][j]=++cnt;
}
}
for(int i=1;i<=n;++i)
{
for(int j=0;j<=m;++j)
{
s[i][j]=++cnt;
}
}
for(int i=0;i<=n;++i)
{
for(int j=0;j<=m;++j)
{
add(h[i][j],s[i][j],a[i][j+1]);
add(h[i][j],h[i][j+1],a[i][j+1]+a[i+1][j+1]);
add(h[i][j],s[i+1][j],a[i+1][j+1]);
add(s[i][j],h[i][j+1],a[i+1][j+1]);
add(s[i][j],s[i+1][j],a[i+1][j]+a[i+1][j+1]);
add(s[i][j],h[i][j],a[i+1][j]);
add(h[i][j+1],s[i+1][j],a[i+1][j]);
add(h[i][j+1],h[i][j],a[i][j]+a[i+1][j]);
add(h[i][j+1],s[i][j],a[i][j]);
add(s[i+1][j],h[i][j],a[i][j]);
add(s[i+1][j],s[i][j],a[i][j]+a[i][j+1]);
add(s[i+1][j],h[i][j+1],a[i][j+1]);
}
}
std::priority_queue<std::pair<int,int>> que;
std::fill(dis+1,dis+1+cnt,INT_MAX/2);
dis[h[0][1]]=dis[s[1][0]]=0;
que.push({0,h[0][1]});
que.push({0,s[1][0]});
while(!que.empty())
{
int now=que.top().second;
if(que.top().first+dis[now])
{
que.pop();
continue;
}
que.pop();
for(auto i:e[now])
{
if(dis[i.first]>dis[now]+i.second)
{
que.push({-(dis[i.first]=dis[now]+i.second),i.first});
}
}
}
std::cout<<std::min(dis[h[n][m]],dis[s[n][m]])<<std::endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
input:
4 6 .##... .#.... ##.... ....#.
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3788kb
input:
20 30 ...########################### #..########################### ...########################### ...########################### .############################# ...########################### ...########################### #..########################### ...########################### ..#...............
output:
7
result:
wrong answer 1st numbers differ - expected: '11', found: '7'