# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
796057 |
2023-07-28T05:34:28 Z |
이동현(#10071) |
Council (JOI23_council) |
C++17 |
|
4000 ms |
340772 KB |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int NS = (int)3e5 + 4;
int n, m;
int a[NS], cnt[20], ans[NS];
int dp[21][1 << 20];
int id[21][1 << 20];
int dp2[21][1 << 20];
int id2[21][1 << 20];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for(int i = 0; i < n; ++i){
for(int j = 0; j < m; ++j){
int x;
cin >> x;
a[i] |= (x << j);
cnt[j] += x;
}
}
vector<int> ncnt;
for(int i = 0; i < n; ++i){
int bt = 0, top = 0;
for(int j = 0; j < m; ++j){
if(cnt[j] >= n / 2 && cnt[j] < n / 2 + 2){
if(!i){
ncnt.push_back(cnt[j]);
}
if(a[i] & (1 << j)){
bt |= 1 << top;
}
++top;
}
if(cnt[j] >= n / 2 + 2){
ans[i] += 1;
}
}
a[i] = bt;
}
m = (int)ncnt.size();
for(int i = 0; i < m; ++i){
cnt[i] = ncnt[i];
}
for(int i = 0; i <= m; ++i){
for(int j = 0; j < 1 << m; ++j){
dp[i][j] = dp2[i][j] = 1000;
}
}
for(int i = 0; i < n; ++i){
dp[m][a[i]] = 0;
id[m][a[i]] = i;
}
int all = (1 << m) - 1;
for(int i = m - 1; i >= 0; --i){
for(int j = 0; j < 1 << m; ++j){
vector<pair<int, int>> srt(4);
srt[0] = {dp[i + 1][j | (1 << i)] + !!(j & (1 << i)), id[i + 1][j | (1 << i)]};
srt[1] = {dp2[i + 1][j | (1 << i)] + !!(j & (1 << i)), id2[i + 1][j | (1 << i)]};
srt[2] = {dp[i + 1][j & (all - (1 << i))], id[i + 1][j & (all - (1 << i))]};
srt[3] = {dp2[i + 1][j & (all - (1 << i))], id2[i + 1][j & (all - (1 << i))]};
sort(srt.begin(), srt.end());
dp[i][j] = srt[0].first, id[i][j] = srt[0].second;
dp2[i][j] = srt[1 + (srt[0].second == srt[1].second)].first, id2[i][j] = srt[1 + (srt[0].second == srt[1].second)].second;
}
}
for(int i = 0; i < n; ++i){
int bt = 0;
ans[i] += m;
for(int j = 0; j < m; ++j){
int v = cnt[j] - n / 2 - !!(a[i] & (1 << j));
if(!v){
bt |= (1 << j);
}
if((a[i] & (1 << j)) && cnt[j] == n / 2){
--ans[i];
}
}
// cout << a[i] << ' ' << bt << ' ' << dp[0][bt] << endl;
int mn = (int)1e9;
for(int j = 0; j < n; ++j){
if(i != j){
mn = min(mn, __builtin_popcount(bt & a[j]));
}
}
ans[i] -= mn;
// ans[i] -= (id[0][bt] == i ? dp2[0][bt] : dp[0][bt]);
cout << ans[i] << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
710 ms |
336840 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
733 ms |
336856 KB |
Output is correct |
11 |
Correct |
820 ms |
336840 KB |
Output is correct |
12 |
Correct |
865 ms |
337928 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
852 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
0 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Correct |
0 ms |
468 KB |
Output is correct |
34 |
Correct |
0 ms |
468 KB |
Output is correct |
35 |
Correct |
1 ms |
468 KB |
Output is correct |
36 |
Correct |
0 ms |
468 KB |
Output is correct |
37 |
Correct |
1 ms |
596 KB |
Output is correct |
38 |
Correct |
1 ms |
596 KB |
Output is correct |
39 |
Correct |
1 ms |
852 KB |
Output is correct |
40 |
Correct |
1 ms |
852 KB |
Output is correct |
41 |
Correct |
8 ms |
4436 KB |
Output is correct |
42 |
Correct |
0 ms |
468 KB |
Output is correct |
43 |
Correct |
0 ms |
468 KB |
Output is correct |
44 |
Correct |
8 ms |
4436 KB |
Output is correct |
45 |
Correct |
9 ms |
4476 KB |
Output is correct |
46 |
Correct |
77 ms |
36940 KB |
Output is correct |
47 |
Correct |
1 ms |
980 KB |
Output is correct |
48 |
Correct |
0 ms |
596 KB |
Output is correct |
49 |
Correct |
78 ms |
36940 KB |
Output is correct |
50 |
Correct |
84 ms |
37048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
710 ms |
336840 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
733 ms |
336856 KB |
Output is correct |
11 |
Correct |
820 ms |
336840 KB |
Output is correct |
12 |
Correct |
865 ms |
337928 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
852 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
0 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Correct |
0 ms |
468 KB |
Output is correct |
34 |
Correct |
0 ms |
468 KB |
Output is correct |
35 |
Correct |
1 ms |
468 KB |
Output is correct |
36 |
Correct |
0 ms |
468 KB |
Output is correct |
37 |
Correct |
1 ms |
596 KB |
Output is correct |
38 |
Correct |
1 ms |
596 KB |
Output is correct |
39 |
Correct |
1 ms |
852 KB |
Output is correct |
40 |
Correct |
1 ms |
852 KB |
Output is correct |
41 |
Correct |
8 ms |
4436 KB |
Output is correct |
42 |
Correct |
0 ms |
468 KB |
Output is correct |
43 |
Correct |
0 ms |
468 KB |
Output is correct |
44 |
Correct |
8 ms |
4436 KB |
Output is correct |
45 |
Correct |
9 ms |
4476 KB |
Output is correct |
46 |
Correct |
77 ms |
36940 KB |
Output is correct |
47 |
Correct |
1 ms |
980 KB |
Output is correct |
48 |
Correct |
0 ms |
596 KB |
Output is correct |
49 |
Correct |
78 ms |
36940 KB |
Output is correct |
50 |
Correct |
84 ms |
37048 KB |
Output is correct |
51 |
Correct |
24 ms |
384 KB |
Output is correct |
52 |
Correct |
24 ms |
380 KB |
Output is correct |
53 |
Correct |
24 ms |
396 KB |
Output is correct |
54 |
Correct |
977 ms |
340772 KB |
Output is correct |
55 |
Correct |
22 ms |
340 KB |
Output is correct |
56 |
Correct |
130 ms |
37440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Execution timed out |
4041 ms |
2688 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Execution timed out |
4041 ms |
2688 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Execution timed out |
4041 ms |
2688 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Execution timed out |
4041 ms |
2688 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
710 ms |
336840 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
733 ms |
336856 KB |
Output is correct |
11 |
Correct |
820 ms |
336840 KB |
Output is correct |
12 |
Correct |
865 ms |
337928 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
852 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
0 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Correct |
0 ms |
468 KB |
Output is correct |
34 |
Correct |
0 ms |
468 KB |
Output is correct |
35 |
Correct |
1 ms |
468 KB |
Output is correct |
36 |
Correct |
0 ms |
468 KB |
Output is correct |
37 |
Correct |
1 ms |
596 KB |
Output is correct |
38 |
Correct |
1 ms |
596 KB |
Output is correct |
39 |
Correct |
1 ms |
852 KB |
Output is correct |
40 |
Correct |
1 ms |
852 KB |
Output is correct |
41 |
Correct |
8 ms |
4436 KB |
Output is correct |
42 |
Correct |
0 ms |
468 KB |
Output is correct |
43 |
Correct |
0 ms |
468 KB |
Output is correct |
44 |
Correct |
8 ms |
4436 KB |
Output is correct |
45 |
Correct |
9 ms |
4476 KB |
Output is correct |
46 |
Correct |
77 ms |
36940 KB |
Output is correct |
47 |
Correct |
1 ms |
980 KB |
Output is correct |
48 |
Correct |
0 ms |
596 KB |
Output is correct |
49 |
Correct |
78 ms |
36940 KB |
Output is correct |
50 |
Correct |
84 ms |
37048 KB |
Output is correct |
51 |
Correct |
24 ms |
384 KB |
Output is correct |
52 |
Correct |
24 ms |
380 KB |
Output is correct |
53 |
Correct |
24 ms |
396 KB |
Output is correct |
54 |
Correct |
977 ms |
340772 KB |
Output is correct |
55 |
Correct |
22 ms |
340 KB |
Output is correct |
56 |
Correct |
130 ms |
37440 KB |
Output is correct |
57 |
Correct |
1 ms |
340 KB |
Output is correct |
58 |
Execution timed out |
4041 ms |
2688 KB |
Time limit exceeded |
59 |
Halted |
0 ms |
0 KB |
- |