QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#252275 | #6739. Teleport | ucup-team191# | WA | 31ms | 107216kb | C++14 | 1.4kb | 2023-11-15 17:31:00 | 2023-11-15 17:31:00 |
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 bio[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;
while (q.size())
{
int i=q.front().x,j=q.front().y,d=dis[i][j];
q.pop();
if (i==n-1 && j==n-1)
{
cout<<d<<en;
exit(0);
}
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 || bio[i1][j1]) continue;
if (h[i1][j1]=='*') continue;
bio[i1][j1]=1;
dis[i1][j1]=d+1;
q.push({i1,j1});
}
for (int u=1;u<=k/2;++u)
{
int i1=i+u,j1=j+u;
if (i1<0 || j1<0 || i1>=n || j1>=n || bio[i1][j1]) break;
if (h[i1][j1]=='*') continue;
bio[i1][j1]=1;
dis[i1][j1]=d+1;
q.push({i1,j1});
}
for (int u=0;u<=(k-1)/2;++u)
{
int i1=j+u+1,j1=i+u;
if (i1<0 || j1<0 || i1>=n || j1>=n || bio[i1][j1]) break;
if (h[i1][j1]=='*') continue;
bio[i1][j1]=1;
dis[i1][j1]=d+1;
q.push({i1,j1});
}
}
cout<<-1<<en;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 102928kb
input:
3 2 .*. .*. ...
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 103304kb
input:
3 3 .*. .*. ...
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: -100
Wrong Answer
time: 31ms
memory: 107216kb
input:
961 4 ...*.*..*.....*.*..*..*..*.*.*.*.....*.....*....*..*...*....*.........*....*....*...*......*..*..*...*..*...*.....*...*...*.*.*.........**..**.......*.......*...*...*.*.*........*....*..*..*...*.....*.*......**.**..**...*..*.**.....*....*.*.*..*..*..*.*..*.*..*......*..*..*.*......*...*.*...*....
output:
547
result:
wrong answer 1st numbers differ - expected: '540', found: '547'