QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#125869 | #6739. Teleport | Liberty12619 | WA | 44ms | 59768kb | C++20 | 1.9kb | 2023-07-17 20:26:44 | 2023-07-17 20:26:45 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define x first
#define y second
using namespace std;
const int N = 5e3+10,M = 1<<22,mod = 998244353,INF=1e15;
typedef pair<int,int>PII;
typedef pair<PII,int>PIII;
typedef long long LL;
int dist[N][N],ne[N][N];
char s[N][N];
void solve()
{
int n,k;
cin>>n>>k;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
dist[i][j]=-1;
dist[1][1]=0;
for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
queue<PII>q;
if(s[1][1]=='.') q.push({1,1});
int dx[4]={0,-1,0,1},dy[4]={1,0,-1,0};
auto ph = [&](int tx,int ty,int x,int y)
{
dist[tx][ty]=dist[x][y]+1;
if(tx==n&&ty==n)
{
cout<<dist[tx][ty]<<endl;
exit(0);
}
q.push({tx,ty});
};
while(q.size())
{
auto it = q.front();
q.pop();
int x = it.x,y=it.y;
int tmp = min({k/2,n-x,n-y});
for(int i=ne[x][y]+1;i<=tmp;i++)
{
int tx = i+x,ty=i+y;
ne[tx][ty]=max(ne[tx][ty],tmp);
if(dist[tx][ty]==-1&&s[tx][ty]=='.') ph(tx,ty,x,y);
}
ne[x][y]=max(ne[x][y],tmp);
int rx = y+1,ry=x;
if(dist[rx][ry]==-1&&s[rx][ry]=='.') ph(rx,ry,x,y);
tmp = min({(k-1)/2,n-rx,n-ry});
for(int i=ne[rx][ry]+1;i<=tmp;i++)
{
int tx = i+rx,ty=i+ry;
ne[tx][ty]=max(ne[tx][ty],tmp);
if(dist[tx][ty]==-1&&s[tx][ty]=='.') ph(tx,ty,x,y);
}
ne[rx][ry]=max(ne[rx][ry],tmp);
for(int i=0;i<4;i++)
{
int tx = x+dx[i],ty=y+dy[i];
if(dist[tx][ty]==-1&&s[tx][ty]=='.')ph(tx,ty,x,y);
}
}
cout<<-1<<endl;
}
signed main()
{
int T =1;
//cin>>T;
while(T--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5668kb
input:
3 2 .*. .*. ...
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5656kb
input:
3 3 .*. .*. ...
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: -100
Wrong Answer
time: 44ms
memory: 59768kb
input:
961 4 ...*.*..*.....*.*..*..*..*.*.*.*.....*.....*....*..*...*....*.........*....*....*...*......*..*..*...*..*...*.....*...*...*.*.*.........**..**.......*.......*...*...*.*.*........*....*..*..*...*.....*.*......**.**..**...*..*.**.....*....*.*.*..*..*..*.*..*.*..*......*..*..*.*......*...*.*...*....
output:
689
result:
wrong answer 1st numbers differ - expected: '540', found: '689'