QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#666504#5116. ContestsRepeaterWA 451ms109856kbC++201.8kb2024-10-22 18:50:152024-10-22 18:50:22

Judging History

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

  • [2024-10-22 18:50:22]
  • 评测
  • 测评结果:WA
  • 用时:451ms
  • 内存:109856kb
  • [2024-10-22 18:50:15]
  • 提交

answer

#include <bits/stdc++.h>

int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	int n, m; std::cin >> n >> m;
	std::vector a(m, std::vector<int>(n)), rk(m, std::vector<int>(n));
	for(int i = 0; i < m; i++)
		for(int j = 0; j < n; j++)
			std::cin >> a[i][j], a[i][j]--;

	for(int i = 0; i < m; i++)
		for(int j = 0; j < n; j++)
			rk[i][a[i][j]] = j;

	int log = std::__lg(n) + 1;
	std::vector f(n, std::vector(log + 1, std::vector<int>(m, n)));

	for(int x = 0; x < m; x++)
	{
		for(int y = 0; y < m; y++) // x -> y
		{
			std::vector<int> min(n);
			min[n - 1] = rk[y][a[x][n - 1]];
			for(int i = n - 2; i >= 0; i--)
				min[i] = std::min(min[i + 1], rk[y][a[x][i]]);

			for(int i = 0; i < n - 1; i++) f[a[x][i]][0][y] = std::min(f[a[x][i]][0][y], min[i + 1]);
		}
	}

	for(int j = 1; j <= log; j++)
		for(int i = 0; i < n; i++)
			for(int x = 0; x < m; x++)
				for(int y = 0; y < m; y++)
					f[i][j][x] = std::min({f[i][j][x], f[i][j - 1][x], f[a[y][f[i][j - 1][y]]][j - 1][x]});

	int q; std::cin >> q;
	while(q--)
	{
		int x, y; std::cin >> x >> y;
		x--, y--;

		bool ok = false;
		for(int i = 0; i < m; i++)
			if(rk[i][x] < rk[i][y])
				ok = true;

		if(ok)
		{
			std::cout << 1 << "\n";
			continue;
		}

		std::vector<int> cur(m);
		for(int i = 0; i < m; i++) cur[i] = rk[i][x];
		int ans = 0;
		for(int i = log; i >= 0; i--)
		{
			auto tmp = cur;
			for(int j = 0; j < m; j++)
				for(int k = 0; k < m; k++)
					tmp[k] = std::min(f[a[j][cur[j]]][i][k], tmp[k]);

			bool flg = true;
			for(int j = 0; j < m; j++)
				if(tmp[j] <= rk[j][y]) flg = false;

			if(flg)
			{
				ans |= 1 << i;
				cur = tmp;
			}
		}

		if(ans == (1 << (log + 1)) - 1) std::cout << -1 << "\n";
		else std::cout << ans + 2 << "\n";
	}

	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3620kb

input:

6 2
1 3 2 5 4 6
2 1 4 3 6 5
4
1 4
5 3
6 1
5 2

output:

1
2
5
3

result:

ok 4 number(s): "1 2 5 3"

Test #2:

score: 0
Accepted
time: 2ms
memory: 4208kb

input:

998 5
1 2 6 3 4 5 7 11 8 9 14 12 13 10 15 16 18 19 20 17 23 22 21 26 24 25 27 29 30 28 32 31 34 33 37 38 39 35 40 36 41 43 42 46 44 48 45 47 51 49 50 56 52 57 53 54 55 62 58 59 63 64 60 65 66 61 67 69 70 68 71 73 74 75 72 78 77 79 82 76 81 85 84 80 86 87 83 88 90 91 89 92 96 98 94 95 97 101 93 103 1...

output:

94
-1
1
1
1
21
1
153
-1
1
19
-1
25
1
1
1
80
1
1
1
1
-1
1
36
102
1
1
1
30
92
1
1
-1
37
36
60
1
1
1
1
1
1
1
1
16
-1
-1
1
1
-1
-1
1
1
140
1
1
77
1
60
1
1
1
4
90
1
1
-1
36
93
1
1
17
148
1
1
1
136
-1
-1
1
28
-1
-1
32
180
1
-1
-1
1
1
1
56
-1
75
25
115
122
1
-1
1
1
2
1
1
1
11
-1
1
-1
1
76
-1
127
-1
1
1
6
1...

result:

ok 1000 numbers

Test #3:

score: 0
Accepted
time: 451ms
memory: 109736kb

input:

99997 5
13846 76247 14430 82900 22678 13000 88476 33335 50407 77862 3545 90269 94531 98082 56502 14027 27673 54173 42855 59901 40095 36046 32844 88104 38879 84883 45979 3117 80875 18985 43692 81119 8682 6390 99780 18979 73738 26817 37612 38509 34976 81565 9953 33844 61610 17678 38492 57218 96547 157...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
2
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
2
1
1
1
1
1
1
1
1
1
1
...

result:

ok 99998 numbers

Test #4:

score: 0
Accepted
time: 440ms
memory: 109736kb

input:

99997 5
64625 15368 86064 79628 49377 9409 53118 61183 39656 22147 23771 67307 29014 79512 84377 58635 22778 53648 4152 26331 30475 34473 93457 71345 50206 78514 10202 79575 95432 58462 32326 57380 93587 91341 33160 73433 41107 82641 9128 5017 12999 59528 75815 4202 27655 3280 4141 54932 34121 38658...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
1
2
2
1
1
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 99998 numbers

Test #5:

score: 0
Accepted
time: 440ms
memory: 109776kb

input:

99997 5
58514 57682 42105 43145 8158 20242 20371 16614 7432 98349 48955 1535 4647 61696 36695 33096 46689 30136 6830 55342 96730 39847 58695 2068 18778 68294 47448 19033 30216 24916 41318 40936 31337 47955 76457 32267 52220 62105 4457 9621 77701 4356 9567 70502 10743 93158 96758 72007 65570 69266 42...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
2
1
1
1
1
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 99998 numbers

Test #6:

score: 0
Accepted
time: 445ms
memory: 109856kb

input:

99997 5
12123 79135 7559 8378 73864 21681 29911 71042 91841 13981 9981 45225 28803 66972 74201 42242 38116 88036 31114 89177 39353 46329 26445 76354 87347 27193 23943 17744 60549 17213 227 99561 22027 77161 66720 30489 11161 88192 34007 31368 89832 10883 78161 7264 1328 32989 7519 61525 28614 96023 ...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
...

result:

ok 99998 numbers

Test #7:

score: 0
Accepted
time: 447ms
memory: 109776kb

input:

99997 5
18291 50708 25258 22267 24292 80896 48412 10059 76253 78698 79475 71080 94605 70762 26399 46328 38921 21637 21059 692 10980 19770 43518 86172 40349 51705 30507 9704 11265 22490 34825 5209 18337 2623 86178 95377 39724 31360 70797 53882 47298 34237 18673 30555 33241 26670 11605 80604 69497 842...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
1
1
1
2
1
1
2
1
1
1
1
1
1
...

result:

ok 99998 numbers

Test #8:

score: -100
Wrong Answer
time: 241ms
memory: 106560kb

input:

99998 1
70242 55692 47154 96102 27579 6889 66745 92632 39813 25663 25647 53493 39170 27398 6217 37894 32165 15352 43981 75150 37853 79002 35076 78592 54779 29726 14716 24896 1890 78236 52141 75129 72669 1162 92653 70522 18962 30745 48956 88916 84086 43644 45589 33178 29088 71530 41141 65654 96266 80...

output:

1
-1
1
1
-1
-1
1
-1
-1
1
1
1
1
-1
1
-1
1
-1
-1
-1
1
1
-1
1
1
-1
1
-1
-1
1
-1
1
-1
-1
-1
1
-1
-1
1
1
-1
1
-1
-1
1
-1
-1
1
1
-1
1
1
-1
-1
1
1
1
-1
-1
-1
1
-1
1
-1
-1
-1
-1
-1
1
1
-1
1
1
-1
1
1
-1
-1
-1
1
1
-1
1
-1
1
1
-1
1
-1
-1
-1
1
-1
1
-1
1
1
-1
1
-1
-1
-1
-1
1
-1
1
-1
-1
1
-1
1
-1
-1
-1
1
-1
-1
-1...

result:

wrong answer 5164th numbers differ - expected: '-1', found: '5'