QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#725402 | #9224. Express Eviction | Okuchiri# | WA | 1ms | 6544kb | C++20 | 3.9kb | 2024-11-08 17:29:00 | 2024-11-08 17:29:00 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
string s[52];
ll dis[52*52*16+10],head[52*52*16+10],tot,answer,n,m;
struct kkk
{
ll to,next,len;
}e[60000007];
inline ll f(ll x,ll y,ll s0,ll s1,ll s2,ll s3)
{
// cout<<x<<' '<<y<<' '<<s0<<' '<<s1<<' '<<s2<<' '<<s3<<endl;
return x*51*16+y*16+s3*8+s2*4+s1*2+s0;
}
inline void add(ll x,ll y,ll len)
{
// cout<<x<<"->"<<y<<':'<<len<<endl;
tot++;
e[tot].to=y;
e[tot].next=head[x];
e[tot].len=len;
head[x]=tot;
}
struct kk
{
ll lo,x;
kk(){}
kk(ll a,ll b)
{
lo=a;
x=b;
}
inline bool operator<(const kk &p)const
{
return x>p.x;
}
};
priority_queue<kk>P;
void solve()
{
cin >> n >> m;
// cout<<n<<' '<<m<<endl;
for(ll i=1;i<=n;i++)
{
cin>>s[i];
s[i]="."+s[i];
}
memset(dis,127,sizeof(dis));
for(ll i=0;i<=n;i++)
{
for(ll j=0;j<=m;j++)
{
// cout<<"IJ:"<<i<<' '<<j<<endl;
ll st[4];
for(ll k=0;k<16;k++)
{
ll p=k;
st[0]=p%2;p/=2;
st[1]=p%2;p/=2;
st[2]=p%2;p/=2;
st[3]=p;
// cout<<k<<" SELF\n";
for(ll o=0;o<=3;o++)
{
if(st[o]==1)
{
ll stt[4]={st[0],st[1],st[2],st[3]};
stt[o]--;
add(f(i,j,st[0],st[1],st[2],st[3]),f(i,j,stt[0],stt[1],stt[2],stt[3]),1);
}
}
// cout<<"SWITCH\n";
if(st[0]==0&&st[3]==0&&j<m)
{
ll x,y;
if(i>=1&&j+2<=m&&s[i][j+2]=='#')x=1;
else x=0;
if(i+1<=n&&j+2<=m&&s[i+1][j+2]=='#')y=1;
else y=0;
add(f(i,j,st[0],st[1],st[2],st[3]),f(i,j+1,x,0,0,y),0);
}
if(st[0]==0&&st[1]==0&&i>0)
{
ll x,y;
if(i-1>=1&&j+1<=m&&s[i-1][j+1]=='#')x=1;
else x=0;
if(i-1>=1&&j>=1&&s[i-1][j]=='#')y=1;
else y=0;
add(f(i,j,st[0],st[1],st[2],st[3]),f(i-1,j,x,y,0,0),0);
}
if(st[1]==0&&st[2]==0&&j>0)
{
ll x,y;
if(i>=1&&j-1>=1&&s[i][j-1]=='#')x=1;
else x=0;
if(i+1<=n&&j-1>=1&&s[i+1][j-1]=='#')y=1;
else y=0;
add(f(i,j,st[0],st[1],st[2],st[3]),f(i,j-1,0,x,y,0),0);
}
if(st[2]==0&&st[3]==0&&i<n)
{
ll x,y;
if(i+2<=n&&j>=1&&s[i+2][j]=='#')x=1;
else x=0;
if(i+2<=n&&j+1<=m&&s[i+2][j+1]=='#')y=1;
else y=0;
add(f(i,j,st[0],st[1],st[2],st[3]),f(i+1,j,0,0,x,y),0);
}
}
}
}
ll ss=0;
if(s[1][1]=='#')ss=8;
P.push(kk(ss,0));
answer=dis[0];
while(!P.empty())
{
ll lo=P.top().lo,x=P.top().x;
P.pop();
if(x>=dis[lo])continue;
// cout<<lo<<'-'<<x<<endl;
dis[lo]=x;
for(ll i=head[lo];i;i=e[i].next)
{
ll to=e[i].to;
if(dis[to]>dis[lo]+e[i].len)
{
dis[to]=dis[lo]+e[i].len+1;
P.push(kk(to,dis[to]-1));
}
}
}
for(ll i=0;i<16;i++)
{
answer=min(answer,dis[n*51*16+m*16+i]);
}
cout<<answer;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll T = 1;
while(T--)
{
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5980kb
input:
4 6 .##... .#.... ##.... ....#.
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 6544kb
input:
20 30 ...########################### #..########################### ...########################### ...########################### .############################# ...########################### ...########################### #..########################### ...########################### ..#...............
output:
7
result:
wrong answer 1st numbers differ - expected: '11', found: '7'