QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#535855 | #9224. Express Eviction | PhantomThreshold# | WA | 1ms | 3632kb | C++20 | 1.6kb | 2024-08-28 15:49:34 | 2024-08-28 15:49:34 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
const int inf=0x3f3f3f3f;
int n,m;
cin>>n>>m;
vector<string> s(n+5);
for(int i=1;i<=n;i++)
{
cin>>s[i];
s[i]=' '+s[i]+' ';
}
s[0]=s[n+1]=string(m+5,' ');
const int N=(n+1)*(m+1)*2;
vector<vector<pair<int,int>>> G(N+5);
auto addedge=[&](int u,int v,int w)
{
// cerr<<"addedge "<<u<<' '<<v<<' '<<w<<endl;
G[u].emplace_back(v,w);
};
auto hs=[&](int x,int y,int ty)
{
return ty*(n+1)*(m+1)+x*(m+1)+y+1;
};
for(int i=0;i<=n;i++)
{
for(int j=0;j<=m;j++)
{
{
int w=(s[i][j]=='#')+(s[i][j+1]=='#')+(s[i+1][j]=='#')+(s[i+1][j+1]=='#');
addedge(hs(i,j,0),hs(i,j,1),w);
}
if(i<n)
{
//down
int w=(s[i+1][j]=='#')+(s[i+1][j+1]=='#');
addedge(hs(i,j,1),hs(i+1,j,0),-w);
addedge(hs(i+1,j,1),hs(i,j,0),-w);
}
if(j<m)
{
//right
int w=(s[i][j+1]=='#')+(s[i+1][j+1]=='#');
addedge(hs(i,j,1),hs(i,j+1,0),-w);
addedge(hs(i,j+1,1),hs(i,j,0),-w);
}
}
}
int S=hs(0,0,0),T=hs(n,m,1);
vector<int> dis(N+5,inf),inq(N+5);
dis[S]=0;
queue<int> q;
q.push(S);inq[S]=1;
while(not q.empty())
{
int u=q.front();q.pop();
inq[u]=0;
// cerr<<"go "<<u<<' '<<dis[u]<<endl;
for(auto [v,w]:G[u])
{
if(dis[v]>dis[u]+w)
{
dis[v]=dis[u]+w;
if(inq[v]==0)
{
inq[v]=1;
q.push(v);
}
}
}
}
cout<<dis[T]<<endl;
/*
for(int i=0;i<=n;i++)
for(int j=0;j<=m;j++)
{
cerr<<i<<' '<<j<<' '<<0<<' '<<dis[hs(i,j,0)]<<"\n";
cerr<<i<<' '<<j<<' '<<1<<' '<<dis[hs(i,j,1)]<<"\n";
}
*/
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3540kb
input:
4 6 .##... .#.... ##.... ....#.
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3632kb
input:
20 30 ...########################### #..########################### ...########################### ...########################### .############################# ...########################### ...########################### #..########################### ...########################### ..#...............
output:
12
result:
wrong answer 1st numbers differ - expected: '11', found: '12'