ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#212792 | #3828. B | Baron2102 | 0 | 0ms | 0kb | C++ | 1.2kb | 2024-10-20 11:16:17 | 2024-10-20 14:38:48 |
answer
#include <bits/stdc++.h>
using namespace std;
int a[1000][1000];
struct node{
int x,y;
int ans[1000]={};
int dep;
}q[10000];
int zx[4]={0,1,-1,0};
int zy[4]={1,0,0,-1};
bool Hash[1000][1000];
node find(int n,int m){
node ans;
for(int i=1;i<=n;i++)
for(int j=1;i<=m;j++)
if(a[i][j]==0){
ans.x=i;
ans.y=j;
return ans;
}
}
int main(){
int t;
cin>>t;
while(t--){
int n,m;
cin>>n>>m;
memset(a,sizeof(a),-1);
memset(Hash,sizeof(Hash),false);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cin>>a[i][j];
int t=1,w=1;
node n0;
n0=find(n,m);
n0.dep=1;
q[t]=n0;
while(t<=w){
n0=q[t];
for(int i=0;i<4;i++){
int nx=n0.x+zx[i],ny=n0.y+zy[i];
if(nx<1||ny<1||nx>n||ny>m) continue;
if(Hash[nx][ny]) continue;
if(n0.ans[n0.dep]<a[nx][ny]) continue;
Hash[nx][ny]=true;
node n1;
n1.x=nx,n1.y=ny,memcpy(n1.ans,n0.ans,sizeof(n0.ans)),n1.dep=n0.dep+1,n1.ans[n1.dep]=a[nx][ny];
q[++w]=n1;
if(q[w].ans[q[w].dep]=n*m-1){
cout<<q[w].dep;
for(int j=1;j<=q[w].dep;j++)
cout<<q[w].ans[j]<<' ';
cout<<endl;
goto TURN;
}
}
t++;
}
TURN:;
}
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 0
Dangerous Syscalls
Test #1:
score: 0
Dangerous Syscalls
input:
10 3 3 0 1 2 3 4 5 6 7 8 3 3 0 1 2 3 4 5 6 8 7 3 3 0 1 2 3 4 5 7 6 8 3 3 0 1 2 3 4 5 7 8 6 3 3 0 1 2...
output:
result:
Subtask #2:
score: 0
Dangerous Syscalls
Test #3:
score: 0
Dangerous Syscalls
input:
10 22 45 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33...
output:
result:
Subtask #3:
score: 0
Dangerous Syscalls
Test #5:
score: 0
Dangerous Syscalls
input:
10 2 100000 143604 106821 145034 44402 118718 156663 77133 28800 81890 12336 191537 118894 103331 75...
output:
result:
Subtask #4:
score: 0
Dangerous Syscalls
Test #6:
score: 0
Dangerous Syscalls
input:
10 1 200000 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32...
output:
result:
Subtask #5:
score: 0
Dangerous Syscalls
Test #7:
score: 0
Dangerous Syscalls
input:
10 145 1379 140324 86968 96426 123781 39754 103720 60835 118904 114639 53717 27146 110309 39232 5608...