QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#708520#2992. 劈配TheZone100 ✓23ms12252kbC++204.8kb2024-11-03 23:09:242024-11-03 23:09:25

Judging History

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

  • [2024-11-03 23:09:25]
  • 评测
  • 测评结果:100
  • 用时:23ms
  • 内存:12252kb
  • [2024-11-03 23:09:24]
  • 提交

answer

#include <bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define mp make_pair

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

template <typename T> bool chkMax(T &x, T y) { return (y > x) ? x = y, 1 : 0; }
template <typename T> bool chkMin(T &x, T y) { return (y < x) ? x = y, 1 : 0; }

template <typename T> void inline read(T &x) {
    int f = 1; x = 0; char s = getchar();
    while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); }
    while (s <= '9' && s >= '0') x = x * 10 + (s ^ 48), s = getchar();
    x *= f;
}

const int N = 205, S = 20;

int C, n, m, b[N], a[N][N], s[N], c[N];

struct E{
	int next, v;
} e[1000005];

int numE;

struct Match{
	bool vis[N];
	vector<int> g[N];
	int head[N], cnt[N];
	void inline bf() {
		for (int u = 1; u <= n; u++) {
			int now = 0;
			for (int i = head[u]; i; i = e[i].next) {
				e[++numE] = e[i];
				if (!now) head[u] = numE;
				else e[now].next = numE;
				now = numE;
			}
		}
	}
	bool XFind(int u) {
		for (int v: g[u]) {
			if (vis[v]) continue;
			vis[v] = 1;
			if (cnt[v] < b[v]) {
				return 1;
			} else {
				for (int i = head[v]; i; i = e[i].next) {
					int w = e[i].v;
					if (find(w)) {
						return 1;
					}
				}
			}
		}
		return 0;
	}
	bool find(int u) {
		for (int v: g[u]) {
			if (vis[v]) continue;
			vis[v] = 1;
			if (cnt[v] < b[v]) {
				cnt[v]++;
				e[++numE] = (E) { head[v], u };
				head[v] = numE;
				return 1;
			} else {
				int la = 0;
				for (int i = head[v]; i; i = e[i].next) {
					int w = e[i].v;
					if (find(w)) {
						if (!la) head[v] = e[i].next;
						else e[la].next = e[i].next;
						e[++numE] = (E) { head[v], u };
						head[v] = numE;
						return 1;
					}
					la = i;
				}
			}
		}
		return 0;
	}
	void inline add(int x, int y) {
		g[x].pb(y);
	}
	bool chk(int x) {
		memset(vis, 0, sizeof vis);
		return find(x);
	}
	bool XChk(int x) {
		memset(vis, 0, sizeof vis);
		return XFind(x);
	}
} t[N], cur;

bool inline chk(int p, int x, int v) {
	cur = t[p];
	cur.bf();
	for (int i = 1; i <= m; i++)
		if (a[x][i] && a[x][i] <= v) cur.add(x, i);
	return cur.XChk(x);
}

void inline work1() {
	for (int i = 1; i <= n; i++) {
		int l = 1, r = m + 1;
		while (l < r) {
			int mid = (l + r) >> 1;
			if (chk(i - 1, i, mid)) r = mid;
			else l = mid + 1;
		}
		c[i] = r;
		printf("%d ", r);
		t[i] = t[i - 1];
		t[i].bf();
		if (r <= m) {
			for (int j = 1; j <= m; j++)
				if (a[i][j] == r) t[i].add(i, j);
			t[i].chk(i);
		}	 
	}
	puts("");
}

void inline work2() {
	for (int i = 1; i <= n; i++) {
		int l = 0, r = i;
		while (l < r) {
			int mid = (l + r) >> 1;
			if (chk(i - mid - 1, i, s[i])) r = mid;
			else l = mid + 1;
		}
		printf("%d ", r);
		
	}
	puts("");
	
}

void inline clr() {
	numE = 0;
}

int main() {
	int T; read(T); read(C);
	while (T--) {
		read(n), read(m);
		for (int i = 1; i <= m; i++) read(b[i]);
		for (int i = 1; i <= n; i++) 
			for (int j = 1; j <= m; j++) read(a[i][j]);
		for (int i = 1; i <= n; i++) read(s[i]);
		work1();
		work2();
		clr();
	}
    return 0;
}



















































































































































































































































































































































































































































































































































































































































































































































































































































Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 1ms
memory: 6448kb

input:

5 1
10 1
10
1
1
1
1
1
1
1
1
1
1
1 1 1 1 1 1 1 1 1 1
10 1
1
1
1
1
1
1
1
1
1
1
1
1 1 1 1 1 1 1 1 1 1
9 1
2
1
1
1
1
1
1
1
1
1
1 1 1 1 1 1 1 1 1
10 1
1
1
1
1
1
1
1
1
1
1
1
1 1 1 1 1 1 1 1 1 1
10 1
4
1
1
1
1
1
1
1
1
1
1
1 1 1 1 1 1 1 1 1 1

output:

1 1 1 1 1 1 1 1 1 1 
0 0 0 0 0 0 0 0 0 0 
1 2 2 2 2 2 2 2 2 2 
0 1 2 3 4 5 6 7 8 9 
1 1 2 2 2 2 2 2 2 
0 0 1 2 3 4 5 6 7 
1 2 2 2 2 2 2 2 2 2 
0 1 2 3 4 5 6 7 8 9 
1 1 1 1 2 2 2 2 2 2 
0 0 0 0 1 2 3 4 5 6 

result:

ok 10 lines

Test #2:

score: 10
Accepted
time: 1ms
memory: 6244kb

input:

5 2
10 2
10 10
1 1
2 2
2 2
2 2
1 1
1 1
2 2
1 1
1 1
1 1
2 2 2 2 2 2 2 2 2 2
8 2
1 1
1 0
0 2
0 1
1 0
0 2
0 2
2 0
1 0
2 2 2 2 2 2 2 2
10 2
1 1
0 2
2 0
0 1
2 0
2 0
2 0
1 0
0 1
1 0
1 0
2 2 2 2 2 2 2 2 2 2
8 2
1 1
0 1
2 0
1 0
0 2
0 1
0 1
1 0
1 0
2 2 2 2 2 2 2 2
10 2
2 3
0 1
0 1
0 1
1 0
0 1
0 2
0 1
0 2
1 0...

output:

1 2 2 2 1 1 2 1 1 1 
0 0 0 0 0 0 0 0 0 0 
1 2 3 3 3 3 3 3 
0 0 1 3 3 4 6 7 
2 2 3 3 3 3 3 3 3 3 
0 0 2 2 3 4 5 7 7 8 
1 2 3 3 3 3 3 3 
0 0 1 3 4 5 5 6 
1 1 1 1 3 3 3 3 1 3 
0 0 0 0 2 3 4 5 0 7 

result:

ok 10 lines

Test #3:

score: 10
Accepted
time: 1ms
memory: 5892kb

input:

5 3
10 3
10 10 10
2 2 2
1 1 1
3 3 3
1 1 1
2 2 2
3 3 3
2 2 2
2 2 2
1 1 1
1 1 1
3 2 3 1 2 2 2 3 2 1
8 3
1 1 1
3 3 0
0 1 3
0 1 1
0 1 3
2 0 3
2 0 1
2 0 1
2 0 3
2 1 1 3 3 2 2 2
10 3
2 2 1
1 1 0
0 1 2
0 1 2
2 0 2
0 1 2
0 2 2
2 2 0
0 2 2
0 1 2
1 1 0
1 1 1 1 1 1 2 1 2 2
10 3
1 2 1
3 0 2
2 2 0
2 0 3
3 0 3
2 ...

output:

2 1 3 1 2 3 2 2 1 1 
0 0 0 0 0 6 0 0 0 0 
3 1 1 4 4 4 4 4 
1 0 0 1 2 3 4 6 
1 1 1 2 2 4 4 4 4 4 
0 0 0 4 2 6 2 8 4 5 
2 2 2 4 4 4 4 4 4 4 
1 2 3 4 2 3 7 8 9 7 
3 3 1 1 3 2 1 4 
1 2 0 0 5 6 0 1 

result:

ok 10 lines

Test #4:

score: 10
Accepted
time: 7ms
memory: 5832kb

input:

5 1
100 100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 3...

output:

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

result:

ok 10 lines

Test #5:

score: 10
Accepted
time: 7ms
memory: 7680kb

input:

5 1
100 100
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 ...

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 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

result:

ok 10 lines

Test #6:

score: 10
Accepted
time: 19ms
memory: 9556kb

input:

5 1
200 200
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

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

result:

ok 10 lines

Test #7:

score: 10
Accepted
time: 18ms
memory: 9100kb

input:

5 1
200 200
200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 ...

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 1 1 1 1 1 1 1 1 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 10 lines

Test #8:

score: 10
Accepted
time: 5ms
memory: 6852kb

input:

5 10
100 100
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100...

output:

66 24 33 43 52 68 38 70 16 48 90 88 3 43 7 20 79 39 81 48 18 63 30 6 5 72 68 30 23 20 73 26 44 6 72 54 40 33 28 2 91 52 14 25 79 82 45 83 6 48 13 55 89 9 34 74 9 26 40 75 57 88 6 62 39 14 44 82 64 83 25 56 24 72 4 16 45 33 54 79 37 68 86 47 73 80 28 56 89 3 54 60 84 38 58 63 42 10 59 56 
1 0 0 0 5 0...

result:

ok 10 lines

Test #9:

score: 10
Accepted
time: 23ms
memory: 9880kb

input:

5 10
200 200
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

121 168 40 167 21 32 79 158 70 14 49 71 69 143 46 80 17 50 5 144 136 70 160 123 112 136 20 46 54 7 47 67 53 184 148 65 39 115 63 46 91 51 6 178 180 138 168 169 132 157 130 178 151 163 144 18 185 137 56 42 30 74 94 111 41 115 114 31 13 186 110 82 61 9 141 58 117 154 78 139 154 76 152 138 184 189 48 1...

result:

ok 10 lines

Test #10:

score: 10
Accepted
time: 15ms
memory: 12252kb

input:

5 10
200 200
200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200...

output:

74 73 14 171 36 16 175 90 116 29 66 56 61 52 15 121 65 134 181 67 169 6 89 165 60 16 128 118 150 1 43 55 35 87 114 53 38 67 153 50 62 43 120 181 50 55 23 3 17 173 46 36 4 13 54 171 29 109 95 40 93 138 22 156 130 70 175 62 11 137 120 164 61 100 3 19 134 13 16 178 35 124 156 108 145 131 91 133 106 109...

result:

ok 10 lines