QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#221143#6515. Path PlanninghazeWA 7ms3860kbC++201.8kb2023-10-21 10:05:192023-10-21 10:05:20

Judging History

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

  • [2023-10-21 10:05:20]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:3860kb
  • [2023-10-21 10:05:19]
  • 提交

answer

#include<bits/stdc++.h>
#define irep(i,l,r) for(int (i) = (l); (i) <= (r); ++(i))
#define drep(i,r,l) for(int (i) = (r); (i) >= (l); --(i))
#define ceil(pp,qq) (((pp)>0)^((qq)>0)?-abs(pp)/abs(qq):(pp)%(qq)?(pp)/(qq)+1:(pp)/(qq))
#define floor(pp,qq) (((pp)>0)^((qq)>0)?-ceil(abs(pp),abs(qq)):(pp)/(qq))
#define ll long long
#define LL __int128
using namespace std;

inline ll read(){
	char ch = getchar();
	ll s = 0; bool w = 0;
	while(!isdigit(ch)){if(ch == '-')w = 1;ch = getchar();}
	while(isdigit(ch))s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
	return w ? - s : s;
}

inline char rc(){
	char ch = getchar();
	while(1){
		if(ch >= 'A' && ch <= 'Z')return ch;
		if(ch >= 'a' && ch <= 'z')return ch;
		ch = getchar();
	}
}

template<class T1, class T2>
T1 min(T1 AA, T2 BB){return AA > BB ? BB : AA;}
template<class T1, class T2>
T1 max(T1 AA, T2 BB){return AA < BB ? BB : AA;}

const int itinf = 1e9;
const ll llinf = 4e18;
const int mod = 1000000007;
const int N = 500009;

void solve(){
	int n = read(), m = read();
	vector a(n, vector(m, int()));
	vector<int>g(n * m);
	irep(i, 0, n - 1){
		irep(j, 0, m - 1){
			g[read()] = i * m + j;
		}
	}
	map<int, array<int, 2>> f;
	/*
	f[i] -> [l,r)
	*/
	int ans = 0;
	for(ans = 0; ans < n * m; ++ ans){
		int loc = g[ans];
		int i = loc / m, j = loc % m;
		if(f.contains(i)){
			auto [l,r] = f[i];
			l = min(l, j), r = max(r, j + 1);
			f[i] = {l,r};
		}
		else
		{
			f[i] = {j, j + 1};
		}
		auto [l,r] = f[i];
		auto it = f.find(i);
		
		if(f.find(i) != f.begin() &&
		 -- it -> second[1] > l)break;
		it = f.find(i);
		if(++ it != f.end() && 
		it -> second[0] < r)break;
	}
	printf("%d\n", min(ans + 1, n * m));
	return;
}

int main(){
	int T = read();
	while(T --){
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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:

7
3
6
3
3
3
5
4
4
3
4
4
6
5
4
4
6
7
2
3
6
8
3
2
3
4
5
2
5
5
5
3
5
3
7
2
3
4
1
3
6
3
4
4
3
4
9
5
3
5
2
2
2
5
3
3
2
5
3
6
3
4
4
5
8
2
2
2
6
7
2
2
3
6
4
5
7
5
3
7
5
2
4
3
3
7
6
4
3
4
7
3
2
5
4
3
4
5
2
4
3
8
5
2
3
7
10
5
7
4
4
3
3
4
3
4
4
5
5
6
2
4
4
3
5
6
4
5
2
5
3
6
3
7
6
2
3
4
2
3
8
1
5
2
7
5
2
4
5
5...

result:

wrong answer 1st numbers differ - expected: '9', found: '7'