QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#72725#5116. ContestsAK_DreamWA 3ms26336kbC++141.5kb2023-01-18 16:40:422023-01-18 16:40:43

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-18 16:40:43]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:26336kb
  • [2023-01-18 16:40:42]
  • 提交

answer

#include <bits/stdc++.h>
#define N 100005
using namespace std;

int n, m, a[5][N], b[5][N];
int p[18][N][5];

int main() {
	scanf("%d %d", &n, &m);
	for (int j = 0; j < m; j++) {
		for (int i = 1; i <= n; i++) {
			scanf("%d", &a[j][i]);
			b[j][a[j][i]] = i;
		}
	}
	memset(p[0], 0x3f, sizeof(p[0]));
	for (int u = 0; u < m; u++) for (int v = 0; v < m; v++) {
		int mn = n+1;
		for (int i = n; i; i--) {
			int x = a[u][i];
			mn = min(mn, b[v][x]);
			p[0][x][v] = min(p[0][x][v], mn);
		}
	}
	for (int l = 1; (1<<l) <= n; l++) {
		for (int i = 1; i <= n; i++) {
			for (int u = 0; u < m; u++) {
				p[l][i][u] = p[l-1][i][u];
				for (int v = 0; v < m; v++) {
					p[l][i][u] = min(p[l][i][u], p[l-1][a[v][p[l-1][i][v]]][u]);
				}
			}
		}
	}
	int Q; scanf("%d", &Q);
	while (Q--) {
		int x, y; scanf("%d %d", &x, &y);
		int t[5] = {0}, t2[5] = {0}, flg = 0;
		for (int u = 0; u < m; u++) {
			t[u] = b[u][x];
			if (t[u] < b[u][y]) { flg = 1; break; }
		}
		if (flg) { puts("1"); continue; }
		int ans = 2, ok = 0;
		for (int l = 17; ~l; l--) {
			memset(t2, 0x3f, sizeof(t2));
			for (int u = 0; u < m; u++) {
				t2[u] = t[u];
				for (int v = 0; v < m; v++) {
					t2[u] = min(t2[u], p[l][a[v][t[v]]][u]);
				}
			}
			flg = 0;
			for (int u = 0; u < m; u++) {
				if (t2[u] < b[u][y]) { flg = 1; break; }
			}
			if (!flg) memcpy(t, t2, sizeof(t)), ans += 1<<l;
			else ok = 1;
		}
		printf("%d\n", ok?ans:-1);
	}
	return 0;
}

詳細信息

Test #1:

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

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

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
1025
1
1
1
21
1
153
1025
1
19
1025
25
1
1
1
80
1
1
1
1
1025
1
36
102
1
1
1
30
92
1
1
1025
37
36
60
1
1
1
1
1
1
1
1
16
1025
1025
1
1
1025
1025
1
1
140
1
1
77
1
60
1
1
1
4
90
1
1
1025
36
93
1
1
17
148
1
1
1
136
1025
1025
1
28
1025
1025
32
180
1
1025
1025
1
1
1
56
1025
75
25
115
122
1
1025
1
1
2
1
1...

result:

wrong answer 2nd numbers differ - expected: '-1', found: '1025'