QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#357869#6515. Path PlanningPorNPtree#WA 17ms9784kbC++201000b2024-03-19 14:04:192024-03-19 14:04:19

Judging History

你现在查看的是最新测评结果

  • [2024-03-19 14:04:19]
  • 评测
  • 测评结果:WA
  • 用时:17ms
  • 内存:9784kb
  • [2024-03-19 14:04:19]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
#define P pair<int,int>
#define fi first
#define se second
#define fr(x) freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);
using namespace std;
const int N=1e6+5;
int T,n,m,s;P w[N],f[N<<1];bool v[N<<1];
vector<int>a[N];
inline bool chk(int x)
{
	for(int i=0;i<=n+m;i++) v[i]=0; 
	for(int i=0;i<=x;i++)
	{
		auto [u,v]=w[i];
		if(::v[u+v]) return 0;::v[u+v]=1;
		f[u+v]={u,v};
	}
	for(int i=2;i<n+m;i++)
	{
		auto [u,v]=f[i];auto [U,V]=f[i+1];
		if(!::v[i]||!::v[i+1]) continue;
		if(!((u+1==U&&v==V)||(u==U&&v+1==V))) return 0;
	}return 1;
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin>>T;
	while(T--)
	{
		cin>>n>>m;s=n*m;
		for(int i=1;i<=n;i++)
		{
			a[i].resize(m+3);
			for(int j=1;j<=m;j++) cin>>a[i][j],w[a[i][j]]={i,j};
		}
		int l=0,r=s-1,mid,ans;
		while(l<=r)
		{
			mid=(l+r)>>1;
			if(chk(mid)) ans=mid,l=mid+1;
			else r=mid-1;
		}cout<<ans+1<<"\n";
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 9784kb

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: 17ms
memory: 9740kb

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
6
7
6
9
7
4
6
7
13
9
10
10
6
1
5
7
4
2
10
4
18
5
12
3
7
6
9
4
1
5
6
10
8
5
2
5
3
5
7
13
7
10
2
10
3
6
9
9
3
10
3
3
3
5
8
4
7
7
7
8
8
6
6
5
3
7
7
13
3
3
6
5
4
3
10
5
12
7
2
11
6
7
5
10
9
5
3
10
2
5
3
8
7
10
5
4
10
4
6
5
9
4
10
6
3
5
4
4
7
4
8
4
12
6
4
5
8
6
8
3
7
9
3
6
12
4
6
6
...

result:

wrong answer 11th numbers differ - expected: '5', found: '6'