Submission #784709

# Submission time Handle Problem Language Result Execution time Memory
784709 2023-07-16T12:47:16 Z oscar1f Council (JOI23_council) C++17
56 / 100
4000 ms 37212 KB
#include<bits/stdc++.h>
using namespace std;

const int MAX_PERS=300*1000+5,MAX_PROP=22,MAX_VAL=(1<<20);

int nbPers,nbChoix,rep,val,bascule,minPerdu;
int choix[MAX_PERS][MAX_PROP];
int somme[MAX_PROP];
int nbOccu[MAX_VAL];
int val1[MAX_VAL];
int memo[MAX_VAL];

int compte1(int nb) {
	int nb1=0;
	while (nb>0) {
		nb1+=nb%2;
		nb/=2;
	}
	return nb1;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>nbPers>>nbChoix;
	for (int i=0;i<nbPers;i++) {
		for (int j=0;j<nbChoix;j++) {
			cin>>choix[i][j];
			somme[j]+=choix[i][j];
		}
	}
	if (nbPers<=3000) {
		for (int i=0;i<nbPers;i++) {
			rep=0;
			for (int j=0;j<nbPers;j++) {
				if (i!=j) {
					val=0;
					for (int k=0;k<nbChoix;k++) {
						if (somme[k]-choix[i][k]-choix[j][k]>=nbPers/2) {
							val++;
						}
					}
					rep=max(rep,val);
				}
			}
			cout<<rep<<"\n";
		}
	}
	else {
		for (int i=0;i<(1<<nbChoix);i++) {
			val1[i]=compte1(i);
			memo[i]=-1;
		}
		for (int i=0;i<nbPers;i++) {
			val=0;
			for (int j=0;j<nbChoix;j++) {
				val+=(1<<j)*choix[i][j];
			}
			nbOccu[val]++;
		}
		for (int i=0;i<nbPers;i++) {
			rep=0;
			minPerdu=nbChoix;
			bascule=0;
			val=0;
			for (int j=0;j<nbChoix;j++) {
				val+=(1<<j)*choix[i][j];
				if (somme[j]-choix[i][j]>=nbPers/2) {
					rep++;
					if (somme[j]-choix[i][j]-1<nbPers/2) {
						bascule+=(1<<j);
					}
				}
			}
			if (memo[val]!=-1) {
				cout<<memo[val]<<"\n";
			}
			else {
				nbOccu[val]--;
				for (int j=0;j<(1<<nbChoix);j++) {
					if (nbOccu[j]>0) {
						minPerdu=min(minPerdu,val1[j&bascule]);
					}
				}
				nbOccu[val]++;
				memo[val]=rep-minPerdu;
				cout<<rep-minPerdu<<"\n";
			}
		}
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 0 ms 224 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 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 212 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 340 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 0 ms 224 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 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 212 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 340 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 215 ms 596 KB Output is correct
52 Correct 204 ms 596 KB Output is correct
53 Correct 210 ms 596 KB Output is correct
54 Correct 212 ms 580 KB Output is correct
55 Correct 23 ms 468 KB Output is correct
56 Correct 182 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 53 ms 26760 KB Output is correct
3 Correct 49 ms 26704 KB Output is correct
4 Correct 44 ms 26672 KB Output is correct
5 Correct 54 ms 26700 KB Output is correct
6 Correct 43 ms 26700 KB Output is correct
7 Correct 56 ms 26676 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 23 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 53 ms 26760 KB Output is correct
3 Correct 49 ms 26704 KB Output is correct
4 Correct 44 ms 26672 KB Output is correct
5 Correct 54 ms 26700 KB Output is correct
6 Correct 43 ms 26700 KB Output is correct
7 Correct 56 ms 26676 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 23 ms 600 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 162 ms 26768 KB Output is correct
21 Correct 150 ms 26668 KB Output is correct
22 Correct 162 ms 26768 KB Output is correct
23 Correct 142 ms 27052 KB Output is correct
24 Correct 137 ms 26736 KB Output is correct
25 Correct 160 ms 26756 KB Output is correct
26 Correct 180 ms 26744 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 53 ms 26760 KB Output is correct
3 Correct 49 ms 26704 KB Output is correct
4 Correct 44 ms 26672 KB Output is correct
5 Correct 54 ms 26700 KB Output is correct
6 Correct 43 ms 26700 KB Output is correct
7 Correct 56 ms 26676 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 23 ms 600 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 162 ms 26768 KB Output is correct
21 Correct 150 ms 26668 KB Output is correct
22 Correct 162 ms 26768 KB Output is correct
23 Correct 142 ms 27052 KB Output is correct
24 Correct 137 ms 26736 KB Output is correct
25 Correct 160 ms 26756 KB Output is correct
26 Correct 180 ms 26744 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 298 ms 26892 KB Output is correct
48 Correct 241 ms 34416 KB Output is correct
49 Correct 258 ms 34392 KB Output is correct
50 Correct 192 ms 35396 KB Output is correct
51 Correct 183 ms 35028 KB Output is correct
52 Correct 483 ms 35072 KB Output is correct
53 Correct 517 ms 35392 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 336 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 53 ms 26760 KB Output is correct
3 Correct 49 ms 26704 KB Output is correct
4 Correct 44 ms 26672 KB Output is correct
5 Correct 54 ms 26700 KB Output is correct
6 Correct 43 ms 26700 KB Output is correct
7 Correct 56 ms 26676 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 23 ms 600 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 162 ms 26768 KB Output is correct
21 Correct 150 ms 26668 KB Output is correct
22 Correct 162 ms 26768 KB Output is correct
23 Correct 142 ms 27052 KB Output is correct
24 Correct 137 ms 26736 KB Output is correct
25 Correct 160 ms 26756 KB Output is correct
26 Correct 180 ms 26744 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 298 ms 26892 KB Output is correct
48 Correct 241 ms 34416 KB Output is correct
49 Correct 258 ms 34392 KB Output is correct
50 Correct 192 ms 35396 KB Output is correct
51 Correct 183 ms 35028 KB Output is correct
52 Correct 483 ms 35072 KB Output is correct
53 Correct 517 ms 35392 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 336 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 3764 ms 37212 KB Output is correct
60 Execution timed out 4034 ms 15584 KB Time limit exceeded
61 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 0 ms 224 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 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 212 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 340 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 215 ms 596 KB Output is correct
52 Correct 204 ms 596 KB Output is correct
53 Correct 210 ms 596 KB Output is correct
54 Correct 212 ms 580 KB Output is correct
55 Correct 23 ms 468 KB Output is correct
56 Correct 182 ms 596 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 53 ms 26760 KB Output is correct
59 Correct 49 ms 26704 KB Output is correct
60 Correct 44 ms 26672 KB Output is correct
61 Correct 54 ms 26700 KB Output is correct
62 Correct 43 ms 26700 KB Output is correct
63 Correct 56 ms 26676 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Correct 0 ms 212 KB Output is correct
67 Correct 1 ms 212 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 0 ms 212 KB Output is correct
70 Correct 0 ms 212 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 23 ms 600 KB Output is correct
74 Correct 0 ms 212 KB Output is correct
75 Correct 0 ms 212 KB Output is correct
76 Correct 162 ms 26768 KB Output is correct
77 Correct 150 ms 26668 KB Output is correct
78 Correct 162 ms 26768 KB Output is correct
79 Correct 142 ms 27052 KB Output is correct
80 Correct 137 ms 26736 KB Output is correct
81 Correct 160 ms 26756 KB Output is correct
82 Correct 180 ms 26744 KB Output is correct
83 Correct 1 ms 212 KB Output is correct
84 Correct 0 ms 212 KB Output is correct
85 Correct 0 ms 340 KB Output is correct
86 Correct 0 ms 340 KB Output is correct
87 Correct 1 ms 340 KB Output is correct
88 Correct 1 ms 212 KB Output is correct
89 Correct 1 ms 340 KB Output is correct
90 Correct 0 ms 212 KB Output is correct
91 Correct 0 ms 340 KB Output is correct
92 Correct 2 ms 340 KB Output is correct
93 Correct 1 ms 212 KB Output is correct
94 Correct 0 ms 340 KB Output is correct
95 Correct 0 ms 340 KB Output is correct
96 Correct 1 ms 340 KB Output is correct
97 Correct 0 ms 212 KB Output is correct
98 Correct 0 ms 212 KB Output is correct
99 Correct 1 ms 340 KB Output is correct
100 Correct 0 ms 340 KB Output is correct
101 Correct 1 ms 340 KB Output is correct
102 Correct 0 ms 340 KB Output is correct
103 Correct 298 ms 26892 KB Output is correct
104 Correct 241 ms 34416 KB Output is correct
105 Correct 258 ms 34392 KB Output is correct
106 Correct 192 ms 35396 KB Output is correct
107 Correct 183 ms 35028 KB Output is correct
108 Correct 483 ms 35072 KB Output is correct
109 Correct 517 ms 35392 KB Output is correct
110 Correct 1 ms 212 KB Output is correct
111 Correct 1 ms 336 KB Output is correct
112 Correct 1 ms 212 KB Output is correct
113 Correct 1 ms 340 KB Output is correct
114 Correct 1 ms 340 KB Output is correct
115 Correct 3764 ms 37212 KB Output is correct
116 Execution timed out 4034 ms 15584 KB Time limit exceeded
117 Halted 0 ms 0 KB -