QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#272848 | #6739. Teleport | ychhaha | WA | 43ms | 9200kb | C++17 | 1.4kb | 2023-12-02 19:38:43 | 2023-12-02 19:38:44 |
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});
}
ll k=m;
PLL now={T_T.x,T_T.y};
while(k--) {
now = {now.second + 1, now.first};
if (now.second <= n && Map[now.second][now.first] != '*' && !Vis[now.second][now.first])
q.push({now.second, now.first, T_T.step + 1});
}
}
cout<<"-1\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3568kb
input:
3 2 .*. .*. ...
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3632kb
input:
3 3 .*. .*. ...
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: -100
Wrong Answer
time: 43ms
memory: 9200kb
input:
961 4 ...*.*..*.....*.*..*..*..*.*.*.*.....*.....*....*..*...*....*.........*....*....*...*......*..*..*...*..*...*.....*...*...*.*.*.........**..**.......*.......*...*...*.*.*........*....*..*..*...*.....*.*......**.**..**...*..*.**.....*....*.*.*..*..*..*.*..*.*..*......*..*..*.*......*...*.*...*....
output:
530
result:
wrong answer 1st numbers differ - expected: '540', found: '530'