답안 #890014

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
890014 2023-12-20T10:50:36 Z vjudge1 Council (JOI23_council) C++17
40 / 100
4000 ms 271148 KB
#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define all(a) a.begin(), a.end()
const int N = 3e5;
int ans[N+10];


vector< vector<int> > build(int n, int m, vector< vector<int> > &a){
	
	vector<int> cnt(m);
	for(int i = 0;i < n; i++){
		for(int j = 0;j < m; j++){
			cnt[j]+= a[i][j];
		}
	}
	vector< vector<int> > res(n);
	
	for(int i = 0;i < n; i++){
		for(int j = 0;j < m; j++){
			if(cnt[j] > (n / 2) + 1){
				ans[i]++;
			}
		}
	}
	for(int i = 0;i < n; i++){
		for(int j = 0;j < m; j++){
			if(cnt[j] == n / 2){
				res[i].push_back(a[i][j]);
			}else if(cnt[j] ==  (n / 2) + 1){
				res[i].push_back(a[i][j]);
			}
		}
	}
	return res;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	vector< vector<int> > a(n, vector<int>(m));
	for(int i = 0;i < n; i++){
		for(int j = 0;j < m; j++){
			cin >> a[i][j];
		}
	}
	a = build(n, m, a);
	n = a.size();
	m = a[0].size();
	vector<int> cnt(m);
	int col = 0, col1 = 0;
	for(int i = 0;i < n; i++){
		for(int j = 0;j < m; j++){
			cnt[j]+= a[i][j];
		}
	}
	
	for(int j = 0;j < m; j++){
		if(cnt[j] == n / 2) col+= (1<<j);
		else col1+= (1<<j);
	}
	vector<int> bits(n);
	vector<int> index[(1<<m) + 10];
	for(int i = 0;i < n; i++){
		int mask = 0;
		for(int j = 0;j < m; j++){
			if(a[i][j]){
				mask+= (1<<j);
			}
		}
		bits[i] = mask;
		index[mask].push_back(i);
	}
	
	 vector< vector<int> > mx_index(1<<m, vector<int>(22, -1));
	vector< vector<int> > mn_index(1<<m, vector<int>(22, -1));
	for(int bits = 0; bits < (1<<m); bits++){
		for(int mask = 0; mask < (1<<m); mask++){
			if(index[mask].empty() == false){
				int k = (bits & mask);
				k = __builtin_popcount(k);
				if(index[mask].size() >= 2){
					if(mx_index[bits][k] == -1) mx_index[bits][k] = index[mask][0];
					if(mn_index[bits][k] == -1) mn_index[bits][k] = index[mask].back();
				}else{
					if(mx_index[bits][k] == -1) mx_index[bits][k] = index[mask][0];
					else if(mn_index[bits][k] == -1) mn_index[bits][k] = index[mask][0];
				}
			}
		}
	}
	
		for(int i = 0;i < n; i++){
			int msk = 0, c = 0;
			for(int j = 0;j < m; j++){
				if(bits[i] & (1<<j)){
					if(cnt[j] - 1==  n / 2){
						msk+= (1<<j);
						c++;
					}
				}else{
					if(cnt[j] == n / 2){
						msk+= (1<<j);
						c++;
					}else if(cnt[j] - 1==  n / 2){
						c++;
					}
				}
			}
			int mx = 0;
			for(int bit = 0; bit < 22; bit++){
				if(mn_index[msk][bit] != -1 && mn_index[msk][bit] != i){
					mx = max(mx, c - bit);	
					break;
				}
				if(mx_index[msk][bit] != -1 && mx_index[msk][bit] != i){
					mx = max(mx, c - bit);	
					break;
				}
			}
			
			ans[i]+= mx;
		}
	
	for(int i = 0;i < n; i++) cout << ans[i] << '\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Execution timed out 4086 ms 271148 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Execution timed out 4086 ms 271148 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 57 ms 25104 KB Output is correct
3 Correct 54 ms 23936 KB Output is correct
4 Correct 45 ms 23888 KB Output is correct
5 Correct 58 ms 23888 KB Output is correct
6 Correct 61 ms 33104 KB Output is correct
7 Correct 89 ms 33104 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 57 ms 25104 KB Output is correct
3 Correct 54 ms 23936 KB Output is correct
4 Correct 45 ms 23888 KB Output is correct
5 Correct 58 ms 23888 KB Output is correct
6 Correct 61 ms 33104 KB Output is correct
7 Correct 89 ms 33104 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 238 ms 52056 KB Output is correct
21 Correct 220 ms 52052 KB Output is correct
22 Correct 232 ms 52156 KB Output is correct
23 Correct 150 ms 29796 KB Output is correct
24 Correct 147 ms 28500 KB Output is correct
25 Correct 181 ms 30032 KB Output is correct
26 Correct 250 ms 51912 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 3 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 57 ms 25104 KB Output is correct
3 Correct 54 ms 23936 KB Output is correct
4 Correct 45 ms 23888 KB Output is correct
5 Correct 58 ms 23888 KB Output is correct
6 Correct 61 ms 33104 KB Output is correct
7 Correct 89 ms 33104 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 238 ms 52056 KB Output is correct
21 Correct 220 ms 52052 KB Output is correct
22 Correct 232 ms 52156 KB Output is correct
23 Correct 150 ms 29796 KB Output is correct
24 Correct 147 ms 28500 KB Output is correct
25 Correct 181 ms 30032 KB Output is correct
26 Correct 250 ms 51912 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 3 ms 604 KB Output is correct
46 Correct 1 ms 604 KB Output is correct
47 Correct 708 ms 56768 KB Output is correct
48 Correct 403 ms 56660 KB Output is correct
49 Correct 397 ms 56748 KB Output is correct
50 Correct 194 ms 34388 KB Output is correct
51 Correct 188 ms 33196 KB Output is correct
52 Correct 214 ms 34384 KB Output is correct
53 Correct 1236 ms 56748 KB Output is correct
54 Correct 175 ms 4700 KB Output is correct
55 Correct 0 ms 344 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 172 ms 4700 KB Output is correct
58 Correct 177 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 57 ms 25104 KB Output is correct
3 Correct 54 ms 23936 KB Output is correct
4 Correct 45 ms 23888 KB Output is correct
5 Correct 58 ms 23888 KB Output is correct
6 Correct 61 ms 33104 KB Output is correct
7 Correct 89 ms 33104 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 238 ms 52056 KB Output is correct
21 Correct 220 ms 52052 KB Output is correct
22 Correct 232 ms 52156 KB Output is correct
23 Correct 150 ms 29796 KB Output is correct
24 Correct 147 ms 28500 KB Output is correct
25 Correct 181 ms 30032 KB Output is correct
26 Correct 250 ms 51912 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 3 ms 604 KB Output is correct
46 Correct 1 ms 604 KB Output is correct
47 Correct 708 ms 56768 KB Output is correct
48 Correct 403 ms 56660 KB Output is correct
49 Correct 397 ms 56748 KB Output is correct
50 Correct 194 ms 34388 KB Output is correct
51 Correct 188 ms 33196 KB Output is correct
52 Correct 214 ms 34384 KB Output is correct
53 Correct 1236 ms 56748 KB Output is correct
54 Correct 175 ms 4700 KB Output is correct
55 Correct 0 ms 344 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 172 ms 4700 KB Output is correct
58 Correct 177 ms 4700 KB Output is correct
59 Correct 282 ms 39172 KB Output is correct
60 Execution timed out 4065 ms 57044 KB Time limit exceeded
61 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Execution timed out 4086 ms 271148 KB Time limit exceeded
6 Halted 0 ms 0 KB -