QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#272871 | #6739. Teleport | ychhaha | AC ✓ | 417ms | 80456kb | C++17 | 1.4kb | 2023-12-02 19:45:17 | 2023-12-02 19:45:18 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
const int P = 998244353;
typedef pair<ll,ll> PLL;
const int N = 5010;
const int mod = 1e9 + 7;
int n,m;
string Map[N];
bool Vis[N][N];
ll fx[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
struct Point{
ll x,y,step;
};
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>Map[i],Map[i]=" "+Map[i];
queue<Point> q;
q.push({1,1,0});
while(q.size())
{
auto T_T=q.front();
q.pop();
if(Vis[T_T.x][T_T.y])
continue;
if(T_T.x==n&&T_T.y==n)
{
cout<<T_T.step<<endl;
return 0;
}
Vis[T_T.x][T_T.y]=true;
for(int i=0;i<4;i++)
{
ll dx=T_T.x+fx[i][0];
ll dy=T_T.y+fx[i][1];
if(dx>=1&&dx<=n&&dy>=1&&dy<=n&&Map[dx][dy]!='*'&&!Vis[dx][dy])
q.push({dx,dy,T_T.step+1});
}
PLL now={T_T.x,T_T.y};
for(int i=0;i<=m;i++) {
if(i==0)
now={T_T.x,T_T.y};
else
now = {now.second + 1, now.first};
if (now.first <= n && Map[now.first][now.second] != '*' && !Vis[now.first][now.second])
q.push({now.first, now.second, T_T.step + 1});
}
}
cout<<"-1\n";
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3860kb
input:
3 2 .*. .*. ...
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
3 3 .*. .*. ...
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 31ms
memory: 9396kb
input:
961 4 ...*.*..*.....*.*..*..*..*.*.*.*.....*.....*....*..*...*....*.........*....*....*...*......*..*..*...*..*...*.....*...*...*.*.*.........**..**.......*.......*...*...*.*.*........*....*..*..*...*.....*.*......**.**..**...*..*.**.....*....*.*.*..*..*..*.*..*.*..*......*..*..*.*......*...*.*...*....
output:
540
result:
ok 1 number(s): "540"
Test #4:
score: 0
Accepted
time: 19ms
memory: 14516kb
input:
975 434 .*......*...*....*......*..*...*...**....*....*.......*...*.....*..*..*.*.*..*.*..*..*.*....*.*.*..*...*.*.....*......*.*...*......*..*..*......**..**.......*...*.*..*..*.*.**....*.*.*.....*....**.*..*..**.*..*.....*.*......*..*...*..*...*....**...*....*..*.*.*...........*..*.**.*.*..*.*..**...
output:
5
result:
ok 1 number(s): "5"
Test #5:
score: 0
Accepted
time: 17ms
memory: 10952kb
input:
966 19 ..*.*.*........*.*..*.**..*....*..*..*....*.**..*.*.*..*.*.*..**....*.*.*....*.....*...........*.*..*.....*..*...*....*.*...*.*...*....*...*...*.*.*....*.*....**.*.......*....*.*.*...*..*..*..*.*...*...*...*..*..*..........*.*....*.*......*...*..**....*.*....**.....*..*..*..*.*....*...*..*.*....
output:
104
result:
ok 1 number(s): "104"
Test #6:
score: 0
Accepted
time: 13ms
memory: 12008kb
input:
973 199 ..**.*...*.*...*.*.*.*.**..*.*.*..*......*.....*.*.*..*...**.....*.*..*.*..*...*....*..*...*....*.*...*.*......*..*.*.*.*......**......*.*.*.*.*.*...*...*...*....*......*.*.*.*..*..*..*...*..*.*....*....*.*...*..*..*.*..**.**..*.**....*.*...*..**..**...*......*.....*.....*..*.*.......*.*.*.....
output:
10
result:
ok 1 number(s): "10"
Test #7:
score: 0
Accepted
time: 17ms
memory: 10164kb
input:
984 95 .....*.*...*....*..*....*.*....**.**......*....*.*.*.......*.....*.*..*....*..*....*.*.....*..*.......*.*......*.*....*.....*......*...*....*....*......*....*.*...*........*......*.*....*.*...*....*..**....*.*.*.**....*..*.*..*..*.*......*..*......*.*......*...*......*.......*...*....*...**.....
output:
21
result:
ok 1 number(s): "21"
Test #8:
score: 0
Accepted
time: 417ms
memory: 27444kb
input:
2996 2 ..*..*.....*..*.....*....**..*...........*..*........*..*..*.*..*..*.*.*.**.*.....**.*.......*.......*..*....*.....*..*.*.*....**.....*..**.....*.....*.......*.*.*.*....*...*..*.**......**..*.*...**..*..*......*..*.*...*......*.*.*.*...**.**..*.*........*.*..*...**......*.*..*.*..*....*.*.*.*...
output:
3354
result:
ok 1 number(s): "3354"
Test #9:
score: 0
Accepted
time: 126ms
memory: 80456kb
input:
2905 1023 .........*..*.**.....*...*.*....*.*.**.*..*...*..*....*...*.**.*.*.**..*......*...*.**..*...*..*.........*.........*.*.....**.*.*........*.....*.*....*..*.*.....*..*..*..*.*..*....**...*.*..*....*......*.........*.*.*.*......**.**.**..*.*.*..*..**..*..*...*...*.*.......*..*..*....*.*.........
output:
6
result:
ok 1 number(s): "6"
Test #10:
score: 0
Accepted
time: 134ms
memory: 29944kb
input:
2978 104 .*.........*...**.....*...*........*..*...*.*.*.....*........*.*...*.....*...*....*...*..*...*..*..*....*...*..*.*....*....*...*.......*.*.....*.*.......*.*..*...*.*.......*.*.*..........*.*..*.*..**.*....*.*.*..*...*.*.*.....*....*...*.*.*.*.........*.*.....**.*.*..*.*....*........*...*.**...
output:
58
result:
ok 1 number(s): "58"