QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#252301 | #6739. Teleport | ucup-team191# | TL | 4ms | 104656kb | C++14 | 2.0kb | 2023-11-15 17:51:57 | 2023-11-15 17:51:59 |
Judging History
answer
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
using vl=vector<ll>;
#define pb push_back
#define all(a) begin(a),end(a)
const int N=5010,MOD=1e9+7;
const char en='\n';
const ll LLINF=1ll<<60;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int n,k;
string h[N];
bool bio1[N][N],bio2[N][N];
int dis[N][N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
memset(dis,63,sizeof(dis));
cin>>n>>k;
for (int i=0;i<n;++i) cin>>h[i];
queue<pii> q;
q.push({0,0});
dis[0][0]=0;
bio1[0][0]=bio2[0][0];
while (q.size())
{
int i=q.front().x,j=q.front().y,d=dis[i][j];
//cout<<i<<' '<<j<<' '<<d<<en;
//bio1[i][j]=bio2[i][j]=1;
q.pop();
if (i==n-1 && j==n-1)
{
cout<<d<<en;
exit(0);
}
int u;
for (u=1;u<=k/2;++u)
{
int i1=i+u,j1=j+u;
if (i1<0 || j1<0 || i1>=n || j1>=n) break;
if (bio1[i1][j1]) continue;
if (dis[i1][j1]<=dis[i][j]) break;
if (h[i1][j1]=='*') continue;
}
for (--u;u>0;--u)
{
int i1=i+u,j1=j+u;
if (i1<0 || j1<0 || i1>=n || j1>=n) break;
if (bio1[i1][j1]) continue;
if (h[i1][j1]=='*') continue;
bio2[i1][j1]=1;
dis[i1][j1]=d+1;
q.push({i1,j1});
}
for (u=0;u<=(k-1)/2;++u)
{
int i1=j+u+1,j1=i+u;
if (i1<0 || j1<0 || i1>=n || j1>=n) break;
if (bio1[i1][j1]) continue;
if (dis[i1][j1]<=dis[i][j]) break;
if (h[i1][j1]=='*') continue;
}
for (--u;u>=0;--u)
{
int i1=j+u+1,j1=i+u;
if (i1<0 || j1<0 || i1>=n || j1>=n) break;
if (bio1[i1][j1]) continue;
if (h[i1][j1]=='*') continue;
bio2[i1][j1]=1;
dis[i1][j1]=d+1;
q.push({i1,j1});
}
for (int u=0;u<4;++u)
{
int i1=i+dx[u],j1=j+dy[u];
if (i1<0 || j1<0 || i1>=n || j1>=n) continue;
if (bio1[i1][j1]) continue;
if (bio2[i1][j1]) continue;
if (h[i1][j1]=='*') continue;
bio1[i1][j1]=1;
dis[i1][j1]=d+1;
q.push({i1,j1});
}
}
cout<<-1<<en;
}
详细
Test #1:
score: 100
Accepted
time: 4ms
memory: 104656kb
input:
3 2 .*. .*. ...
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 3ms
memory: 104320kb
input:
3 3 .*. .*. ...
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: -100
Time Limit Exceeded
input:
961 4 ...*.*..*.....*.*..*..*..*.*.*.*.....*.....*....*..*...*....*.........*....*....*...*......*..*..*...*..*...*.....*...*...*.*.*.........**..**.......*.......*...*...*.*.*........*....*..*..*...*.....*.*......**.**..**...*..*.**.....*....*.*.*..*..*..*.*..*.*..*......*..*..*.*......*...*.*...*....