제출 #1308368

#제출 시각아이디문제언어결과실행 시간메모리
1308368sweetwibu2k8Council (JOI23_council)C++20
0 / 100
55 ms48028 KiB
#include <bits/stdc++.h>
using namespace std;

#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define p_q priority_queue
#define bit(n, i) (((n)>>(i))&1)
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector <vector <int> > vvi;

const int M = 3e5 + 6;
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;

void maximize (int &a, int b) { if (a < b) a = b; }
void minimize (int &a, int b) { if (a > b) a = b; }
void add (int &a, int b) { a += b; if (a >= mod) a -= mod; }
void del (int &a, int b) { a -= b; if (a < 0) a += mod; }

int a[M][20];
int b[M][20];
int f[(1 << 22) + 5], g[(1 << 22 + 5)];
int S[M];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
//	freopen (".inp", "r", stdin);
//	freopen (".out", "w", stdout);

	int n, m; cin >> n >> m;
	for (int i = 1; i <= n; i ++)
	{
		int sum = 0;
		for (int j = 0; j < m; j ++)
		{
			cin >> a[i][j];
			b[i][j] = 1 - a[i][j];
			sum += b[i][j] * (1 << j);
			S[j] += a[i][j];
		}
		f[sum] ++;
		g[sum] = __builtin_popcount (sum);
	}
	
	for (int k = 0; k < m; k ++)
		for (int mask = (1 << m) - 1; mask >= 0; mask --)
			if (bit (mask, k) == 1)
			{
				f[mask] += f[mask ^ (1 << k)];
				maximize (g[mask], g[mask ^ (1 << k)]);
			}
				
	int half = n / 2;
	for (int i = 1; i <= n; i ++)
	{
		int needed = 0, always = 0;
		for (int j = 0; j < m; j ++)
		{
			int tmp = S[j] - half - a[i][j];
			if (tmp == 0) needed ^= (1 << j);
			else if (tmp >= 1) always ++;
		}
		cout << always + g[needed] << endl;
	}
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...