QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#900228#2992. 劈配liyujia50 815ms13912kbC++142.6kb2025-02-15 15:00:472025-02-15 15:00:57

Judging History

This is the latest submission verdict.

  • [2025-02-15 15:00:57]
  • Judged
  • Verdict: 50
  • Time: 815ms
  • Memory: 13912kb
  • [2025-02-15 15:00:47]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
const int M = 100005, N = 505;
int TT, C, h[N], ne[M], w[M], s[N], e[M], d[N], cur[N], n, m, a[N], b[N][N], cnt, id[N];
void add(int x, int y, int c){
	ne[++cnt] = h[x], h[x] = cnt, e[cnt] = y, w[cnt] = c;
	ne[++cnt] = h[y], h[y] = cnt, e[cnt] = x, w[cnt] = 0;
}
int bfs(int s, int t){
	queue <int> q; memset(d, -1, sizeof d);
	q.push(s), d[s] = 0;
	while(!q.empty()){
		int t = q.front(); q.pop();
		for(int i = cur[t] = h[t]; ~i; i = ne[i]) if(w[i] && !~d[e[i]])
			q.push(e[i]), d[e[i]] = d[t] + 1;
	}
	return d[t];
}
int find(int x, int mf, int T){
	if(x == T) return mf;
	int flow = 0;
	for(int &i = cur[x]; ~i; i = ne[i]){
		if(flow == mf) break;
		if(!w[i] || d[e[i]] != d[x] + 1) continue;
		int t = find(e[i], min(mf - flow, w[i]), T);
		flow += t, w[i] -= t, w[i ^ 1] += t;
	}
	return flow;
}
int dinic(int S, int T){
	int ans = 0;
	while(~bfs(S, T)) ans += find(S, 114514, T);
	return ans;
}
int mch[N][N], S, T;
vector <int> v[N][N];
void rec(int x){
	memset(h, -1, sizeof h), cnt = -1;
	for(int i = 1; i <= n; i++) add(S, i, 1);
	for(int i = 1; i <= m; i++) add(i + n, T, a[i]), id[i] = cnt - 1;
	for(int i = 1; i <= x; i++)
		for(int j: v[i][b[i][mch[x][i]]]){
			add(i, j + n, 1);
			if(j == mch[x][i]) swap(w[cnt], w[cnt ^ 1]), w[id[j]]--;
		}
}
int chk(int i, int h){
	rec(i - 1);
	for(int j = 1; j <= m; j++) if(b[i][j] <= h && b[i][j]) add(i, j + n, 1);
	return dinic(S, T);
}
int chk2(int i, int h){
	if(h == i) return 1;
	rec(i - h - 1);
	for(int j = 1; j <= m; j++) if(b[i][j] <= s[i] && b[i][j]) add(i, j + n, 1);
	return dinic(S, T);
}
int main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> TT >> C;
	while(TT--){
		cin >> n >> m;
		S = 0, T = n + m + 2;
		for(int i = 1; i <= m; i++) cin >> a[i];
		for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) cin >> b[i][j], v[i][j].clear(), v[i][m + 1].clear();
		for(int i = 1; i <= n; i++) cin >> s[i];
		m++;
		for(int i = 1; i <= n; i++) b[i][m] = m; a[m] = n;
		for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) v[i][b[i][j]].push_back(j);
		for(int i = 1; i <= n; i++){
			int l = 1, r = m;
			while(l < r){
				int mid = l + r >> 1;
				if(chk(i, mid)) r = mid;
				else l = mid + 1;
			}
			chk(i, l);
			cout << l << ' ';
			for(int j = 1; j <= i; j++)
				for(int k = h[j]; ~k; k = ne[k])
					if(!w[k] && e[k]) mch[i][j] = e[k] - n;
		}
		cout << '\n';
		for(int i = 1; i <= n; i++){
			int l = 0, r = i;
			while(l < r){
				int mid = l + r >> 1;
				if(chk2(i, mid)) r = mid;
				else l = mid + 1;
			}
			cout << l << ' ';
		}
		cout << '\n';
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 0ms
memory: 11092kb

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: 0
Wrong Answer
time: 1ms
memory: 11456kb

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 1 1 1 1 1 1 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:

wrong answer 1st lines differ - expected: '1 2 2 2 1 1 2 1 1 1', found: '1 1 1 1 1 1 1 1 1 1 '

Test #3:

score: 0
Wrong Answer
time: 3ms
memory: 11904kb

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 1 1 1 1 1 1 1 1 
0 0 0 0 0 0 0 0 0 0 
3 1 1 4 4 4 4 4 
1 0 0 1 2 3 4 5 
1 1 1 2 1 1 1 1 1 4 
0 0 0 1 2 0 0 5 0 1 
2 2 1 1 4 4 1 4 1 1 
1 2 3 4 1 2 0 0 0 6 
3 1 1 1 1 1 1 1 
1 2 0 0 0 0 0 0 

result:

wrong answer 1st lines differ - expected: '2 1 3 1 2 3 2 2 1 1', found: '2 1 1 1 1 1 1 1 1 1 '

Test #4:

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

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

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

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

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: 0
Wrong Answer
time: 112ms
memory: 12192kb

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

result:

wrong answer 1st lines differ - expected: '66 24 33 43 52 68 38 70 16 48 ...3 54 60 84 38 58 63 42 10 59 56', found: '66 1 1 1 1 1 1 1 1 1 1 1 1 1 1... 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 '

Test #9:

score: 0
Wrong Answer
time: 472ms
memory: 13384kb

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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 1st lines differ - expected: '121 168 40 167 21 32 79 158 70...148 37 110 182 43 192 70 83 149', found: '121 1 1 1 1 1 1 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 '

Test #10:

score: 0
Wrong Answer
time: 815ms
memory: 12472kb

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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 1st lines differ - expected: '74 73 14 171 36 16 175 90 116 ...104 86 16 88 78 139 32 99 51 11', found: '74 1 1 1 1 1 1 1 1 1 1 1 1 1 1... 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 '