QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#666434#5116. ContestsRepeaterWA 2ms4344kbC++201.8kb2024-10-22 18:28:002024-10-22 18:28:07

Judging History

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

  • [2024-10-22 18:28:07]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:4344kb
  • [2024-10-22 18:28:00]
  • 提交

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

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: -100
Wrong Answer
time: 2ms
memory: 4344kb

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:

1818
-1
1
1
1
23
1
2024
-1
1
1042
-1
1039
1
1
1
2000
1
1
1
1
-1
1
1044
2031
1
1
1
1046
1823
1
1
-1
1541
1048
1558
1
1
1
1
1
1
1
1
23
-1
-1
1
1
-1
-1
1
1
1946
1
1
1814
1
1555
1
1
1
6
1989
1
1
-1
1827
1822
1
1
1039
2042
1
1
1
-1
-1
-1
1
1541
-1
-1
1559
2046
1
-1
-1
1
1
1
1992
-1
1801
1798
1998
1998
1
...

result:

wrong answer 1st numbers differ - expected: '94', found: '1818'