답안 #891334

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
891334 2023-12-22T19:06:38 Z iskhakkutbilim Council (JOI23_council) C++17
0 / 100
11 ms 27228 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;
}



pair<int, int> dp[2][1222][1222];
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,0);
	vector<int> bits(n, 0);
	int bpc[1<<20];
	
	for(int i = 0;i < 1<<20; i++){
		bpc[i] = __builtin_popcount(i);
	}
	for(int i = 0;i < n; i++){
		for(int j = 0;j < m; j++){
			bits[i]+= (a[i][j] << j);
			cnt[j]+= a[i][j];
		}
		int m0  = bits[i] & 1023;
		int m1 = bits[i]>>10;		
		for(int j = 0;j < 1024; j++){
			int c = bpc[m1 & j];
			if(dp[0][m0][j].ff == -1){
				dp[0][m0][j] = {c, i};
			}else{
				if(dp[0][m0][j].ff >= c){
					dp[1][m0][j] = dp[0][m0][j];
					dp[0][m0][j] = {c, i};
				}else if(dp[1][m0][j].ff == -1 || dp[1][m0][j].ff >= c){
					dp[1][m0][j] = {c, i};
				}
			}
		}
		
	}
	
	for(int i = 0;i < 2; i++){
		for(int j = 0;j < 1024; j++){
			for(int k = 0;k < 1024; k++){
				dp[i][j][k] = {-1, -1};
			}
		}
	}
	for(int i = 0;i < n; i++){
		int mask = 0, bc = 0;
		for(int j = 0;j < m; j++){
			if(bits[i] & (1<<j)){
				if(cnt[j] == n/2 + 1){
					bc++;
					mask+= (1<<j);
				}
			}else{
				if(cnt[j] == n / 2 + 1) bc++;
				else{
					mask+= (1<<j);
					bc++;
				}
			}
		}
		int mn = m;
		int m0 = mask & 1023;
		int m1 = mask >> 10;
		for(int j = 0;j < 1024; j++){
			int c = bpc[m0 & j];
			if(dp[0][j][m1].ff == -1) continue;
			int kek = 20;
			if(dp[0][j][m1].ss != i && dp[0][j][m1].ss != -1){
				kek = min(kek, dp[0][j][m1].ff);
			}
			if(dp[1][j][m1].ss != i && dp[1][j][m1].ss != -1){
				kek = min(kek, dp[1][j][m1].ff);
			}
			mn = min(mn, kek + c);
		}
		ans[i] = ans[i] + bc - mn;
	}
	
	
	
	for(int i = 0;i < n; i++) cout << ans[i] << '\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 27224 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 27224 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 27228 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 27228 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 27228 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 27228 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 27224 KB Output isn't correct
2 Halted 0 ms 0 KB -