ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#209322 | #3772. 飞行棋 | ranqizhang | 100 | 1030ms | 61104kb | C++11 | 1.1kb | 2024-08-04 09:35:14 | 2024-08-04 12:23:59 |
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1010;
struct node{
vector<int> v;
}mp[N][N];
int n,m;
int a[N][N];
struct qu{
int x;
int y;
int step;
};
int vis[N][N];
void bfs(){
queue<qu> q;
q.push({0,0,0});
vis[0][0]=1;
while(!q.empty()){
qu tmp=q.front();
q.pop();
if(tmp.x==n-1&&tmp.y==m-1){
cout<<tmp.step;
exit(0);
}
// cout<<tmp.x<<' '<<tmp.y<<"\n\n";
for(int i=0;i<mp[tmp.x][tmp.y].v.size();i++){
int tx=mp[tmp.x][tmp.y].v[i]/m;
int ty=mp[tmp.x][tmp.y].v[i]%m;
// cout<<tx<<' '<<ty<<endl;
if(vis[tx][ty]==0){
vis[tx][ty]=1;
q.push({tx,ty,tmp.step+1});
}
}
// cout<<"\n\n";
}
cout<<"No Solution";
}
int main(){
cin>>n>>m;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>a[i][j];
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
// cout<<j+a[i][j]<<endl;
if(i-a[i][j]>=0) mp[i][j].v.push_back((i-a[i][j])*m+j);
if(i+a[i][j]<n) mp[i][j].v.push_back((i+a[i][j])*m+j);
if(j+a[i][j]<m) mp[i][j].v.push_back(i*m+j+a[i][j]);
if(j-a[i][j]>=0) mp[i][j].v.push_back(i*m+j-a[i][j]);
// cout<<i*m+j<<endl;
}
}
bfs();
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 60
Accepted
Test #1:
score: 60
Accepted
time: 11ms
memory: 25148kb
input:
3 3 2 2 3 1 2 3 3 1 1
output:
No Solution
result:
ok 2 tokens
Test #2:
score: 0
Accepted
time: 6ms
memory: 25164kb
input:
7 3 3 3 3 5 4 7 6 7 7 6 1 3 3 4 2 1 1 4 5 1 6
output:
No Solution
result:
ok 2 tokens
Test #3:
score: 0
Accepted
time: 7ms
memory: 25188kb
input:
8 3 4 2 3 4 2 2 6 3 4 5 5 4 3 6 1 2 1 7 6 2 5 1 8 7
output:
No Solution
result:
ok 2 tokens
Test #4:
score: 0
Accepted
time: 13ms
memory: 25232kb
input:
8 6 1 1 5 5 1 7 2 1 8 8 2 8 5 3 2 5 3 2 3 4 1 2 6 2 4 4 8 7 3 3 7 2 3 7 5 3 4 1 5 7 4 8 4 7 3 3 3 2
output:
7
result:
ok "7"
Test #5:
score: 0
Accepted
time: 4ms
memory: 25208kb
input:
7 9 8 1 4 5 7 7 7 4 4 2 7 6 4 8 6 8 3 6 1 9 1 8 5 5 4 8 6 5 9 1 2 4 8 3 7 1 4 9 9 6 1 5 1 4 2 4 1 8 ...
output:
3
result:
ok "3"
Test #6:
score: 0
Accepted
time: 5ms
memory: 25248kb
input:
10 10 7 1 6 8 6 5 5 7 9 9 6 7 7 3 8 3 10 1 8 4 5 10 2 2 10 5 8 3 5 5 7 8 4 6 9 8 3 8 9 5 5 9 3 6 10 ...
output:
6
result:
ok "6"
Subtask #2:
score: 20
Accepted
Test #7:
score: 20
Accepted
time: 8ms
memory: 26232kb
input:
100 100 43 1 34 53 74 81 44 67 8 26 89 21 71 5 95 44 26 63 36 12 14 42 95 96 73 47 96 45 35 55 20 36...
output:
11
result:
ok "11"
Test #8:
score: 0
Accepted
time: 20ms
memory: 26228kb
input:
100 100 59 76 51 65 79 47 38 99 30 54 49 42 61 100 84 98 44 53 22 63 55 11 33 1 52 5 35 20 32 76 24 ...
output:
13
result:
ok "13"
Subtask #3:
score: 20
Accepted
Test #9:
score: 20
Accepted
time: 682ms
memory: 61104kb
input:
1000 1000 692 456 53 655 421 246 495 194 6 409 970 582 974 324 530 571 812 897 729 734 306 180 41 41...
output:
19
result:
ok "19"
Test #10:
score: 0
Accepted
time: 274ms
memory: 29068kb
input:
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 ...
output:
No Solution
result:
ok 2 tokens
Extra Test:
score: 0
Extra Test Passed