# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
918378 |
2024-01-29T18:32:31 Z |
gs25 |
Council (JOI23_council) |
C++17 |
|
315 ms |
53944 KB |
#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V> void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ", ";
__print(x.second);
cerr << '}';
}
template <typename T> void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto &i : x)
cerr << (f++ ? ", " : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
__print(t);
if (sizeof...(v))
cerr << ", ";
_print(v...);
}
#ifndef ONLINE_JUDGE
#define dbg(x...) \
cerr << "\e[91m" << __func__ << ":" << __LINE__ << " [" << #x << "] = ["; \
_print(x); \
cerr << "\e[39m" << endl;
#else
#define dbg(x...)
#endif
#define int long long
#define rrep(i,n) for(int i=1; i<=n; i++)
#define rep(i,n) for(int i=0; i<n; i++)
#define all(v) (v).begin(), (v).end()
#define ff first
#define ss second
#define pb push_back
int popcnt(int x){
assert(x>=0);
return __builtin_popcount(x);
}
int N,M;
const int MAXN = 300100;
int x[MAXN];
int p[30];
int cnt[MAXN];
long long dp[22][3000000];
int comb[300][300];
void solve(){
comb[1][0] = 1;
comb[1][1] = 1;
for(int i=2; i<=22; i++){
for(int j=0; j<=i; j++){
comb[i][j] = comb[i-1][j]+(j!=0 ? comb[i-1][j-1] : 0);
}
}
cin >> N >> M;
int k = N/2;
const int MSK = (1<<M) - 1;
rep(i,N){
rep(j,M){
int a; cin >> a;
if(a==0) continue;
p[j] += a;
x[i] |= (1<<j);
}
x[i] = (~x[i])&MSK;
}
int zeros=0, ones=0, twos=0;
rep(j,M){
if(p[j]>=k+2) zeros |= (1<<j);
if(p[j]==k+1) ones |= (1<<j);
if(p[j]==k) twos |= (1<<j);
}
rep(i,N) cnt[x[i]]++;
for(int i=0; i<M; i++){
for(int j=0; j<=MSK; j++){
if( (j & (1<<i)) ==0) {
cnt[j] += cnt[j^(1<<i)];
}
}
}
for(int j=0; j<= MSK; j++) dp[popcnt(j)][j] = cnt[j];
for(int i=0; i<M; i++){
for(int j=0; j<=MSK; j++){
if(j&(1<<i)){
rep(k,M) dp[k][j] += dp[k][j^(1<<i)];
}
}
}
rep(i,N){
int tmp = (ones&(~x[i])) | (twos&(x[i]));
assert(tmp>=0 && tmp<=MSK);
// tmp maximize tmp | x[j];
int MM = 0;
bool flag = false;
long long sum = 0, first_big=0, id=0;
for(int k=M; k>0; k--){
if(!flag && dp[k][tmp]>0LL){
if(popcnt(tmp&x[i])!=k){
MM = k; break;
}
flag=true;
if(dp[k][tmp]>1){
MM = k; break;
}
first_big=k;
sum = 1;
id = 1;
continue;
}
if(flag){
assert(id<30 && first_big < 30);
sum = comb[first_big][id++];
if(dp[k][tmp]>sum){
MM = k; break;
}
}
}
cout << MM + popcnt(zeros|(ones&x[i])) << "\n";
}
}
int32_t main(void){
ios::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
int t =1; // cin >> t;
while(t--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12636 KB |
Output is correct |
2 |
Correct |
5 ms |
31068 KB |
Output is correct |
3 |
Correct |
2 ms |
12824 KB |
Output is correct |
4 |
Correct |
2 ms |
10736 KB |
Output is correct |
5 |
Runtime error |
12 ms |
5212 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12636 KB |
Output is correct |
2 |
Correct |
5 ms |
31068 KB |
Output is correct |
3 |
Correct |
2 ms |
12824 KB |
Output is correct |
4 |
Correct |
2 ms |
10736 KB |
Output is correct |
5 |
Runtime error |
12 ms |
5212 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
Output is correct |
2 |
Correct |
39 ms |
11944 KB |
Output is correct |
3 |
Correct |
38 ms |
11572 KB |
Output is correct |
4 |
Correct |
37 ms |
9556 KB |
Output is correct |
5 |
Correct |
41 ms |
11856 KB |
Output is correct |
6 |
Correct |
31 ms |
9812 KB |
Output is correct |
7 |
Correct |
45 ms |
11600 KB |
Output is correct |
8 |
Correct |
1 ms |
6488 KB |
Output is correct |
9 |
Correct |
2 ms |
8540 KB |
Output is correct |
10 |
Correct |
2 ms |
10588 KB |
Output is correct |
11 |
Correct |
2 ms |
10584 KB |
Output is correct |
12 |
Correct |
2 ms |
10588 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
2 ms |
10588 KB |
Output is correct |
15 |
Correct |
2 ms |
8540 KB |
Output is correct |
16 |
Correct |
2 ms |
10844 KB |
Output is correct |
17 |
Correct |
3 ms |
10588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
Output is correct |
2 |
Correct |
39 ms |
11944 KB |
Output is correct |
3 |
Correct |
38 ms |
11572 KB |
Output is correct |
4 |
Correct |
37 ms |
9556 KB |
Output is correct |
5 |
Correct |
41 ms |
11856 KB |
Output is correct |
6 |
Correct |
31 ms |
9812 KB |
Output is correct |
7 |
Correct |
45 ms |
11600 KB |
Output is correct |
8 |
Correct |
1 ms |
6488 KB |
Output is correct |
9 |
Correct |
2 ms |
8540 KB |
Output is correct |
10 |
Correct |
2 ms |
10588 KB |
Output is correct |
11 |
Correct |
2 ms |
10584 KB |
Output is correct |
12 |
Correct |
2 ms |
10588 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
2 ms |
10588 KB |
Output is correct |
15 |
Correct |
2 ms |
8540 KB |
Output is correct |
16 |
Correct |
2 ms |
10844 KB |
Output is correct |
17 |
Correct |
3 ms |
10588 KB |
Output is correct |
18 |
Correct |
2 ms |
12632 KB |
Output is correct |
19 |
Correct |
2 ms |
12636 KB |
Output is correct |
20 |
Correct |
142 ms |
28404 KB |
Output is correct |
21 |
Correct |
130 ms |
26192 KB |
Output is correct |
22 |
Correct |
154 ms |
26368 KB |
Output is correct |
23 |
Correct |
132 ms |
28504 KB |
Output is correct |
24 |
Correct |
130 ms |
27976 KB |
Output is correct |
25 |
Correct |
141 ms |
28400 KB |
Output is correct |
26 |
Correct |
151 ms |
28240 KB |
Output is correct |
27 |
Correct |
4 ms |
26972 KB |
Output is correct |
28 |
Correct |
2 ms |
12636 KB |
Output is correct |
29 |
Correct |
2 ms |
14872 KB |
Output is correct |
30 |
Correct |
3 ms |
16732 KB |
Output is correct |
31 |
Correct |
3 ms |
18780 KB |
Output is correct |
32 |
Correct |
4 ms |
20828 KB |
Output is correct |
33 |
Correct |
4 ms |
22876 KB |
Output is correct |
34 |
Correct |
5 ms |
24924 KB |
Output is correct |
35 |
Correct |
4 ms |
26972 KB |
Output is correct |
36 |
Correct |
5 ms |
26972 KB |
Output is correct |
37 |
Correct |
2 ms |
12636 KB |
Output is correct |
38 |
Correct |
3 ms |
14684 KB |
Output is correct |
39 |
Correct |
3 ms |
16732 KB |
Output is correct |
40 |
Correct |
4 ms |
18780 KB |
Output is correct |
41 |
Correct |
3 ms |
20824 KB |
Output is correct |
42 |
Correct |
4 ms |
22876 KB |
Output is correct |
43 |
Correct |
4 ms |
24920 KB |
Output is correct |
44 |
Correct |
4 ms |
26972 KB |
Output is correct |
45 |
Correct |
5 ms |
26968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
Output is correct |
2 |
Correct |
39 ms |
11944 KB |
Output is correct |
3 |
Correct |
38 ms |
11572 KB |
Output is correct |
4 |
Correct |
37 ms |
9556 KB |
Output is correct |
5 |
Correct |
41 ms |
11856 KB |
Output is correct |
6 |
Correct |
31 ms |
9812 KB |
Output is correct |
7 |
Correct |
45 ms |
11600 KB |
Output is correct |
8 |
Correct |
1 ms |
6488 KB |
Output is correct |
9 |
Correct |
2 ms |
8540 KB |
Output is correct |
10 |
Correct |
2 ms |
10588 KB |
Output is correct |
11 |
Correct |
2 ms |
10584 KB |
Output is correct |
12 |
Correct |
2 ms |
10588 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
2 ms |
10588 KB |
Output is correct |
15 |
Correct |
2 ms |
8540 KB |
Output is correct |
16 |
Correct |
2 ms |
10844 KB |
Output is correct |
17 |
Correct |
3 ms |
10588 KB |
Output is correct |
18 |
Correct |
2 ms |
12632 KB |
Output is correct |
19 |
Correct |
2 ms |
12636 KB |
Output is correct |
20 |
Correct |
142 ms |
28404 KB |
Output is correct |
21 |
Correct |
130 ms |
26192 KB |
Output is correct |
22 |
Correct |
154 ms |
26368 KB |
Output is correct |
23 |
Correct |
132 ms |
28504 KB |
Output is correct |
24 |
Correct |
130 ms |
27976 KB |
Output is correct |
25 |
Correct |
141 ms |
28400 KB |
Output is correct |
26 |
Correct |
151 ms |
28240 KB |
Output is correct |
27 |
Correct |
4 ms |
26972 KB |
Output is correct |
28 |
Correct |
2 ms |
12636 KB |
Output is correct |
29 |
Correct |
2 ms |
14872 KB |
Output is correct |
30 |
Correct |
3 ms |
16732 KB |
Output is correct |
31 |
Correct |
3 ms |
18780 KB |
Output is correct |
32 |
Correct |
4 ms |
20828 KB |
Output is correct |
33 |
Correct |
4 ms |
22876 KB |
Output is correct |
34 |
Correct |
5 ms |
24924 KB |
Output is correct |
35 |
Correct |
4 ms |
26972 KB |
Output is correct |
36 |
Correct |
5 ms |
26972 KB |
Output is correct |
37 |
Correct |
2 ms |
12636 KB |
Output is correct |
38 |
Correct |
3 ms |
14684 KB |
Output is correct |
39 |
Correct |
3 ms |
16732 KB |
Output is correct |
40 |
Correct |
4 ms |
18780 KB |
Output is correct |
41 |
Correct |
3 ms |
20824 KB |
Output is correct |
42 |
Correct |
4 ms |
22876 KB |
Output is correct |
43 |
Correct |
4 ms |
24920 KB |
Output is correct |
44 |
Correct |
4 ms |
26972 KB |
Output is correct |
45 |
Correct |
5 ms |
26968 KB |
Output is correct |
46 |
Correct |
6 ms |
31068 KB |
Output is correct |
47 |
Correct |
193 ms |
36436 KB |
Output is correct |
48 |
Correct |
180 ms |
34568 KB |
Output is correct |
49 |
Correct |
185 ms |
34552 KB |
Output is correct |
50 |
Correct |
177 ms |
36692 KB |
Output is correct |
51 |
Correct |
165 ms |
36200 KB |
Output is correct |
52 |
Correct |
194 ms |
36592 KB |
Output is correct |
53 |
Correct |
198 ms |
36872 KB |
Output is correct |
54 |
Correct |
6 ms |
35164 KB |
Output is correct |
55 |
Correct |
7 ms |
35388 KB |
Output is correct |
56 |
Correct |
8 ms |
35160 KB |
Output is correct |
57 |
Correct |
6 ms |
35164 KB |
Output is correct |
58 |
Correct |
6 ms |
35380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
Output is correct |
2 |
Correct |
39 ms |
11944 KB |
Output is correct |
3 |
Correct |
38 ms |
11572 KB |
Output is correct |
4 |
Correct |
37 ms |
9556 KB |
Output is correct |
5 |
Correct |
41 ms |
11856 KB |
Output is correct |
6 |
Correct |
31 ms |
9812 KB |
Output is correct |
7 |
Correct |
45 ms |
11600 KB |
Output is correct |
8 |
Correct |
1 ms |
6488 KB |
Output is correct |
9 |
Correct |
2 ms |
8540 KB |
Output is correct |
10 |
Correct |
2 ms |
10588 KB |
Output is correct |
11 |
Correct |
2 ms |
10584 KB |
Output is correct |
12 |
Correct |
2 ms |
10588 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
2 ms |
10588 KB |
Output is correct |
15 |
Correct |
2 ms |
8540 KB |
Output is correct |
16 |
Correct |
2 ms |
10844 KB |
Output is correct |
17 |
Correct |
3 ms |
10588 KB |
Output is correct |
18 |
Correct |
2 ms |
12632 KB |
Output is correct |
19 |
Correct |
2 ms |
12636 KB |
Output is correct |
20 |
Correct |
142 ms |
28404 KB |
Output is correct |
21 |
Correct |
130 ms |
26192 KB |
Output is correct |
22 |
Correct |
154 ms |
26368 KB |
Output is correct |
23 |
Correct |
132 ms |
28504 KB |
Output is correct |
24 |
Correct |
130 ms |
27976 KB |
Output is correct |
25 |
Correct |
141 ms |
28400 KB |
Output is correct |
26 |
Correct |
151 ms |
28240 KB |
Output is correct |
27 |
Correct |
4 ms |
26972 KB |
Output is correct |
28 |
Correct |
2 ms |
12636 KB |
Output is correct |
29 |
Correct |
2 ms |
14872 KB |
Output is correct |
30 |
Correct |
3 ms |
16732 KB |
Output is correct |
31 |
Correct |
3 ms |
18780 KB |
Output is correct |
32 |
Correct |
4 ms |
20828 KB |
Output is correct |
33 |
Correct |
4 ms |
22876 KB |
Output is correct |
34 |
Correct |
5 ms |
24924 KB |
Output is correct |
35 |
Correct |
4 ms |
26972 KB |
Output is correct |
36 |
Correct |
5 ms |
26972 KB |
Output is correct |
37 |
Correct |
2 ms |
12636 KB |
Output is correct |
38 |
Correct |
3 ms |
14684 KB |
Output is correct |
39 |
Correct |
3 ms |
16732 KB |
Output is correct |
40 |
Correct |
4 ms |
18780 KB |
Output is correct |
41 |
Correct |
3 ms |
20824 KB |
Output is correct |
42 |
Correct |
4 ms |
22876 KB |
Output is correct |
43 |
Correct |
4 ms |
24920 KB |
Output is correct |
44 |
Correct |
4 ms |
26972 KB |
Output is correct |
45 |
Correct |
5 ms |
26968 KB |
Output is correct |
46 |
Correct |
6 ms |
31068 KB |
Output is correct |
47 |
Correct |
193 ms |
36436 KB |
Output is correct |
48 |
Correct |
180 ms |
34568 KB |
Output is correct |
49 |
Correct |
185 ms |
34552 KB |
Output is correct |
50 |
Correct |
177 ms |
36692 KB |
Output is correct |
51 |
Correct |
165 ms |
36200 KB |
Output is correct |
52 |
Correct |
194 ms |
36592 KB |
Output is correct |
53 |
Correct |
198 ms |
36872 KB |
Output is correct |
54 |
Correct |
6 ms |
35164 KB |
Output is correct |
55 |
Correct |
7 ms |
35388 KB |
Output is correct |
56 |
Correct |
8 ms |
35160 KB |
Output is correct |
57 |
Correct |
6 ms |
35164 KB |
Output is correct |
58 |
Correct |
6 ms |
35380 KB |
Output is correct |
59 |
Correct |
223 ms |
45296 KB |
Output is correct |
60 |
Correct |
133 ms |
52644 KB |
Output is correct |
61 |
Correct |
136 ms |
52644 KB |
Output is correct |
62 |
Correct |
146 ms |
52816 KB |
Output is correct |
63 |
Correct |
222 ms |
44788 KB |
Output is correct |
64 |
Correct |
272 ms |
53492 KB |
Output is correct |
65 |
Correct |
265 ms |
53628 KB |
Output is correct |
66 |
Correct |
254 ms |
53944 KB |
Output is correct |
67 |
Correct |
227 ms |
53072 KB |
Output is correct |
68 |
Correct |
271 ms |
53428 KB |
Output is correct |
69 |
Correct |
315 ms |
53804 KB |
Output is correct |
70 |
Correct |
41 ms |
52316 KB |
Output is correct |
71 |
Correct |
42 ms |
52384 KB |
Output is correct |
72 |
Correct |
39 ms |
52312 KB |
Output is correct |
73 |
Correct |
48 ms |
52388 KB |
Output is correct |
74 |
Correct |
51 ms |
52384 KB |
Output is correct |
75 |
Correct |
41 ms |
52316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12636 KB |
Output is correct |
2 |
Correct |
5 ms |
31068 KB |
Output is correct |
3 |
Correct |
2 ms |
12824 KB |
Output is correct |
4 |
Correct |
2 ms |
10736 KB |
Output is correct |
5 |
Runtime error |
12 ms |
5212 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |