QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#141393 | #6515. Path Planning | cy1999 | RE | 1ms | 5456kb | C++11 | 1.1kb | 2023-08-17 11:29:12 | 2023-08-17 11:29:13 |
Judging History
answer
#include<bits/stdc++.h>
//#define int long long
using namespace std;
const int N=1e6+5;
int x[N],y[N];
int t;
int n,m;
vector<pair<int,int> > w;
signed main()
{
cin>>t;
while(t--)
{
int p=-1;
w.clear();
cin>>n>>m;
int u1,u2;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
int a;
cin>>a;
x[a]=i;
y[a]=j;
if(i==1&&j==1)
{
u1=a;
}
if(i==n&&j==m)
{
u2=a;
}
}
}
w.push_back(make_pair(u1,u2));
while(1)
{
int f=0;
p++;
int lw=w.size();
for(int i=0;i<lw;i++)
{
int a=w[i].first;
int b=w[i].second;
if(a==-1)
{
continue;
}
if(x[p]>=x[a]&&x[p]<=x[b]&&y[p]>=y[a]&&y[p]<=y[b])
{
f=1;
if(p==a||p==b)
{
break;
}
w[i].second=w[i].first=-1;
w.push_back(make_pair(p,b));
w.push_back(make_pair(a,p));
break;
}
}
if(f==0)
{
break;
}
}
cout<<p<<endl;
// for(int i=0;i<w.size();i++)
// {
// cout<<"## "<<w[i].first<<" "<<w[i].second<<endl;
// }
assert(p>0&&p<=n+m-1);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5456kb
input:
2 2 3 1 2 4 3 0 5 1 5 1 3 0 4 2
output:
3 5
result:
ok 2 number(s): "3 5"
Test #2:
score: -100
Dangerous Syscalls
input:
10000 2 9 4 0 3 5 2 7 16 11 12 9 13 14 17 10 8 15 1 6 4 8 19 23 22 13 29 4 17 26 30 6 25 3 15 24 18 14 12 8 7 9 27 5 0 10 11 16 31 20 2 28 1 21 1 6 3 2 0 1 4 5 2 3 4 2 0 3 5 1 5 1 4 0 3 2 1 1 3 1 0 2 8 10 9 50 8 0 41 57 60 30 23 65 64 21 36 12 10 5 58 19 38 67 71 52 45 17 77 4 59 51 22 25 56 49 79 2...
output:
9 2 6 3 5 3 14 13 5 9 5 7 6 9 7 4 6 7 13 9 10 9 6 1 5 7 4 2 10 4 18 5 12 3 7 6 9 2 1 5 6 10 8 4 2 5 2 5 7 13 6 10 3