답안 #884509

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
884509 2023-12-07T14:22:40 Z fanwen Council (JOI23_council) C++17
16 / 100
26 ms 9044 KB
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define ll long long
#define file(name)                  \
    if(fopen(name".inp", "r"))      \
        freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout); \

const int MAX = 1e5 + 5;

int n, m, a[MAX], num[25], Min[1 << 10][1 << 10], cnt[1 << 10][1 << 10];
vector <int> adj[1 << 10];

void you_make_it(void) {
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j < m; ++j) {
			int x; cin >> x;
			if(x) a[i] |= (1 << j);
			num[j] += x;
		}
		adj[a[i] & ((1 << m / 2)  - 1)].push_back(a[i] >> (m / 2));	
	}    

	for (int x = 0; x < (1 << m / 2); ++x) {
		for (auto y : adj[x]) cnt[x][y]++;
		for (int y = 0; y < (1 << (m - m / 2)); ++y) {
			Min[x][y] = m + 1;
			for (auto k : adj[x]) {
				Min[x][y] = min(Min[x][y], __builtin_popcount(y & k));
			} 
		}
	}

	for (int i = 1; i <= n; ++i) {
		int res = 0, ans = 0, fir = a[i] & ((1 << (m / 2)) - 1), sec = a[i] >> (m / 2);
		for (int j = 0; j < m; ++j) {
			int total = num[j] - (a[i] >> j & 1);
			if(total > n / 2) ans++;
			else if(total == n / 2) res |= (1 << j);
		}

		int val = m + 1;

		for (int mask = 0; mask < (1 << m / 2); ++mask) {
			if(mask != fir) {
				val = min(val, __builtin_popcount(mask & res) + Min[mask][res >> (m / 2)]);
			} else {
				for (int tmp = 0; tmp < (1 << (m - m / 2)); ++tmp) {
					if(cnt[mask][tmp] and (tmp != sec or cnt[mask][tmp] > 1)) {
						val = min(val, __builtin_popcount(mask & res) + __builtin_popcount(tmp & (res >> (m / 2))));
					}
				}
			}
		}
		cout << ans + __builtin_popcount(res) - val << '\n';
	}

}

signed main() {

#ifdef LOCAL
    freopen("TASK.inp", "r", stdin);
    freopen("TASK.out", "w", stdout);
#endif
    file("council");
    auto start_time = chrono::steady_clock::now();

    cin.tie(0), cout.tie(0) -> sync_with_stdio(0);

    you_make_it();

    auto end_time = chrono::steady_clock::now();

    cerr << "\nExecution time : " << chrono::duration_cast <chrono::milliseconds> (end_time - start_time).count() << "[ms]" << endl;

    return (0 ^ 0);
}

// Dream it. Wish it. Do it.

Compilation message

council.cpp: In function 'int main()':
council.cpp:10:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |         freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout); \
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
council.cpp:70:5: note: in expansion of macro 'file'
   70 |     file("council");
      |     ^~~~
council.cpp:10:49: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |         freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout); \
      |                                          ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
council.cpp:70:5: note: in expansion of macro 'file'
   70 |     file("council");
      |     ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 3 ms 8540 KB Output is correct
6 Correct 4 ms 6492 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 2 ms 8696 KB Output is correct
9 Correct 5 ms 8540 KB Output is correct
10 Correct 3 ms 8540 KB Output is correct
11 Correct 2 ms 8536 KB Output is correct
12 Correct 5 ms 8760 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4440 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4440 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4588 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4700 KB Output is correct
32 Correct 1 ms 4588 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4580 KB Output is correct
37 Correct 1 ms 4440 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 2 ms 4700 KB Output is correct
41 Correct 1 ms 8540 KB Output is correct
42 Correct 2 ms 8540 KB Output is correct
43 Correct 1 ms 8540 KB Output is correct
44 Correct 1 ms 8540 KB Output is correct
45 Correct 1 ms 8540 KB Output is correct
46 Correct 1 ms 8540 KB Output is correct
47 Correct 1 ms 8540 KB Output is correct
48 Correct 2 ms 8540 KB Output is correct
49 Correct 1 ms 8540 KB Output is correct
50 Correct 1 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 3 ms 8540 KB Output is correct
6 Correct 4 ms 6492 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 2 ms 8696 KB Output is correct
9 Correct 5 ms 8540 KB Output is correct
10 Correct 3 ms 8540 KB Output is correct
11 Correct 2 ms 8536 KB Output is correct
12 Correct 5 ms 8760 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4440 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4440 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4588 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4700 KB Output is correct
32 Correct 1 ms 4588 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4580 KB Output is correct
37 Correct 1 ms 4440 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 2 ms 4700 KB Output is correct
41 Correct 1 ms 8540 KB Output is correct
42 Correct 2 ms 8540 KB Output is correct
43 Correct 1 ms 8540 KB Output is correct
44 Correct 1 ms 8540 KB Output is correct
45 Correct 1 ms 8540 KB Output is correct
46 Correct 1 ms 8540 KB Output is correct
47 Correct 1 ms 8540 KB Output is correct
48 Correct 2 ms 8540 KB Output is correct
49 Correct 1 ms 8540 KB Output is correct
50 Correct 1 ms 8540 KB Output is correct
51 Correct 25 ms 6796 KB Output is correct
52 Correct 26 ms 6748 KB Output is correct
53 Correct 25 ms 9044 KB Output is correct
54 Correct 26 ms 8792 KB Output is correct
55 Correct 1 ms 4444 KB Output is correct
56 Correct 13 ms 8796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Runtime error 13 ms 6920 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Runtime error 13 ms 6920 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Runtime error 13 ms 6920 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Runtime error 13 ms 6920 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 3 ms 8540 KB Output is correct
6 Correct 4 ms 6492 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 2 ms 8696 KB Output is correct
9 Correct 5 ms 8540 KB Output is correct
10 Correct 3 ms 8540 KB Output is correct
11 Correct 2 ms 8536 KB Output is correct
12 Correct 5 ms 8760 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4440 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4440 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4588 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4700 KB Output is correct
32 Correct 1 ms 4588 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4580 KB Output is correct
37 Correct 1 ms 4440 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 2 ms 4700 KB Output is correct
41 Correct 1 ms 8540 KB Output is correct
42 Correct 2 ms 8540 KB Output is correct
43 Correct 1 ms 8540 KB Output is correct
44 Correct 1 ms 8540 KB Output is correct
45 Correct 1 ms 8540 KB Output is correct
46 Correct 1 ms 8540 KB Output is correct
47 Correct 1 ms 8540 KB Output is correct
48 Correct 2 ms 8540 KB Output is correct
49 Correct 1 ms 8540 KB Output is correct
50 Correct 1 ms 8540 KB Output is correct
51 Correct 25 ms 6796 KB Output is correct
52 Correct 26 ms 6748 KB Output is correct
53 Correct 25 ms 9044 KB Output is correct
54 Correct 26 ms 8792 KB Output is correct
55 Correct 1 ms 4444 KB Output is correct
56 Correct 13 ms 8796 KB Output is correct
57 Correct 1 ms 4444 KB Output is correct
58 Runtime error 13 ms 6920 KB Execution killed with signal 11
59 Halted 0 ms 0 KB -