QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#141419 | #6515. Path Planning | cy1999 | WA | 48ms | 42656kb | C++20 | 1.6kb | 2023-08-17 11:54:09 | 2023-08-17 11:54:12 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
vector<bool> vis[N];
struct node
{
int x,y;
}a[N];
int n,m;
void work(int x,int y)
{
// cout<<"x="<<x<<" y="<<y<<endl;
int l=x+1,r=n,b1,b2;
if(l>=r)
{
b1=n;
}
else
{
while(l<r)
{
int mid=(l+r)>>1;
if(vis[mid][max(y-1,1)]) r=mid;
else l=mid+1;
}
b1=l;
}
l=1,r=y-1;
if(l==r)
{
b2=0;
}
else
{
while(l<r)
{
int mid=(l+r+1)>>1;
if(vis[min(x+1,n)][mid]) l=mid;
else r=mid-1;
}
b2=l;
}
for(int i=x+1;i<=b1;i++)
{
for(int j=b2+1;j<=y-1;j++)
{
vis[i][j]=1;
}
}
l=1,r=x-1;
if(l==r)
{
b1=0;
}
else
{
while(l<r)
{
int mid=(l+r+1)>>1;
if(vis[mid][min(y+1,m)]) l=mid;
else r=mid-1;
}
b1=l;
}
l=y+1,r=m;
if(l==r)
{
b2=m;
}
else
{
while(l<r)
{
int mid=(l+r)>>1;
if(vis[max(x-1,1)][mid]) r=mid;
else l=mid+1;
}
b2=l;
}
for(int i=b1+1;i<=x-1;i++)
{
for(int j=y+1;j<=b2;j++)
{
vis[i][j]=1;
}
}
// for(int i=1;i<=n;i++)
// {
// for(int j=1;j<=m;j++)
// {
// cout<<vis[i][j]<<" ";
// }
// cout<<endl;
// }
// cout<<endl;
}
int main()
{
int t;
cin>>t;
while(t--)
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
vis[i].clear();
vis[i].push_back(0);
for(int j=1;j<=m;j++)
{
int x;
cin>>x;
a[x].x=i;
a[x].y=j;
vis[i].push_back(0);
}
}
bool flag=0;
for(int i=0;i<n*m;i++)
{
if(vis[a[i].x][a[i].y])
{
cout<<i<<'\n';
flag=1;
break;
}
work(a[i].x,a[i].y);
}
if(!flag)
{
cout<<n*m<<'\n';
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 42544kb
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
Wrong Answer
time: 48ms
memory: 42656kb
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 3 5 7 13 6 10 2 10 3 6 9 8 3 10 2 3 3 5 8 4 7 7 7 8 8 6 6 5 3 7 7 13 3 3 6 7 4 3 10 5 12 7 2 11 6 7 6 10 9 5 3 10 2 5 3 8 7 10 5 5 10 4 6 5 10 4 10 6 3 5 4 5 7 4 8 3 12 6 4 5 8 6 8 3 7 9 3 6 12 4 6 6 ...
result:
wrong answer 47th numbers differ - expected: '2', found: '3'