답안 #784947

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
784947 2023-07-16T20:07:25 Z oscar1f Council (JOI23_council) C++17
48 / 100
4000 ms 64848 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,gratuit,r1,r2;
int choix[MAX_PERS][MAX_PROP];
int somme[MAX_PROP];
vector<int> nbOccu[MAX_VAL];
int val1[MAX_VAL];
int memo[MAX_VAL];
int rest1[MAX_VAL],rest2[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];
		}
	}
	for (int j=0;j<nbChoix;j++) {
		if (somme[j]-2>=nbPers/2) {
			gratuit++;
		}
		else if (somme[j]-1==nbPers/2) {
			for (int i=0;i<nbPers;i++) {
				rest2[i]+=(1<<j)*(1-choix[i][j]);
			}
		}
		else if (somme[j]==nbPers/2) {
			for (int i=0;i<nbPers;i++) {
				rest1[i]+=(1<<j)*(1-choix[i][j]);
			}
		}
	}
	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].push_back(i);
	}
	for (int i=0;i<nbPers;i++) {
		rep=0;
		val=0;
		for (int j=0;j<nbChoix;j++) {
			val+=(1<<j)*choix[i][j];
		}
		if (memo[val]!=-1) {
			cout<<memo[val]<<"\n";
		}
		else {
			for (int j=0;j<(1<<nbChoix);j++) {
				if ((nbOccu[j].size()>0 and j!=val) or nbOccu[j].size()>1) {
					r1=(rest1[i]&rest1[nbOccu[j].back()]);
					r2=(rest2[i]|rest2[nbOccu[j].back()]);
					//cout<<i<<" "<<j<<" : "<<r1<<" "<<r2<<endl;
					//cout<<r1<<" "<<r2<<endl;
					rep=max(rep,gratuit+val1[r1]+val1[r2]);
				}
			}
			memo[val]=rep;
			cout<<rep<<"\n";
		}
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 24916 KB Output is correct
2 Correct 11 ms 24916 KB Output is correct
3 Correct 11 ms 24916 KB Output is correct
4 Correct 11 ms 24916 KB Output is correct
5 Correct 72 ms 33160 KB Output is correct
6 Correct 25 ms 33192 KB Output is correct
7 Correct 34 ms 33100 KB Output is correct
8 Correct 63 ms 33176 KB Output is correct
9 Correct 683 ms 33200 KB Output is correct
10 Correct 32 ms 33164 KB Output is correct
11 Correct 63 ms 33160 KB Output is correct
12 Correct 681 ms 33204 KB Output is correct
13 Correct 12 ms 24916 KB Output is correct
14 Correct 12 ms 24960 KB Output is correct
15 Correct 12 ms 24864 KB Output is correct
16 Correct 12 ms 24896 KB Output is correct
17 Correct 12 ms 24968 KB Output is correct
18 Correct 12 ms 24916 KB Output is correct
19 Correct 12 ms 24964 KB Output is correct
20 Correct 13 ms 24964 KB Output is correct
21 Correct 13 ms 24916 KB Output is correct
22 Correct 12 ms 24916 KB Output is correct
23 Correct 12 ms 24964 KB Output is correct
24 Correct 12 ms 24916 KB Output is correct
25 Correct 12 ms 24916 KB Output is correct
26 Correct 11 ms 24916 KB Output is correct
27 Correct 12 ms 24916 KB Output is correct
28 Correct 13 ms 24960 KB Output is correct
29 Correct 11 ms 24916 KB Output is correct
30 Correct 12 ms 24880 KB Output is correct
31 Correct 13 ms 24916 KB Output is correct
32 Correct 12 ms 24872 KB Output is correct
33 Correct 12 ms 24964 KB Output is correct
34 Correct 11 ms 24916 KB Output is correct
35 Correct 11 ms 24960 KB Output is correct
36 Correct 13 ms 24984 KB Output is correct
37 Correct 12 ms 24964 KB Output is correct
38 Correct 12 ms 24964 KB Output is correct
39 Correct 12 ms 24916 KB Output is correct
40 Correct 12 ms 24916 KB Output is correct
41 Correct 13 ms 25172 KB Output is correct
42 Correct 13 ms 25100 KB Output is correct
43 Correct 13 ms 25044 KB Output is correct
44 Correct 13 ms 25096 KB Output is correct
45 Correct 13 ms 25044 KB Output is correct
46 Correct 16 ms 25988 KB Output is correct
47 Correct 14 ms 25980 KB Output is correct
48 Correct 17 ms 25924 KB Output is correct
49 Correct 14 ms 25976 KB Output is correct
50 Correct 16 ms 26012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 24916 KB Output is correct
2 Correct 11 ms 24916 KB Output is correct
3 Correct 11 ms 24916 KB Output is correct
4 Correct 11 ms 24916 KB Output is correct
5 Correct 72 ms 33160 KB Output is correct
6 Correct 25 ms 33192 KB Output is correct
7 Correct 34 ms 33100 KB Output is correct
8 Correct 63 ms 33176 KB Output is correct
9 Correct 683 ms 33200 KB Output is correct
10 Correct 32 ms 33164 KB Output is correct
11 Correct 63 ms 33160 KB Output is correct
12 Correct 681 ms 33204 KB Output is correct
13 Correct 12 ms 24916 KB Output is correct
14 Correct 12 ms 24960 KB Output is correct
15 Correct 12 ms 24864 KB Output is correct
16 Correct 12 ms 24896 KB Output is correct
17 Correct 12 ms 24968 KB Output is correct
18 Correct 12 ms 24916 KB Output is correct
19 Correct 12 ms 24964 KB Output is correct
20 Correct 13 ms 24964 KB Output is correct
21 Correct 13 ms 24916 KB Output is correct
22 Correct 12 ms 24916 KB Output is correct
23 Correct 12 ms 24964 KB Output is correct
24 Correct 12 ms 24916 KB Output is correct
25 Correct 12 ms 24916 KB Output is correct
26 Correct 11 ms 24916 KB Output is correct
27 Correct 12 ms 24916 KB Output is correct
28 Correct 13 ms 24960 KB Output is correct
29 Correct 11 ms 24916 KB Output is correct
30 Correct 12 ms 24880 KB Output is correct
31 Correct 13 ms 24916 KB Output is correct
32 Correct 12 ms 24872 KB Output is correct
33 Correct 12 ms 24964 KB Output is correct
34 Correct 11 ms 24916 KB Output is correct
35 Correct 11 ms 24960 KB Output is correct
36 Correct 13 ms 24984 KB Output is correct
37 Correct 12 ms 24964 KB Output is correct
38 Correct 12 ms 24964 KB Output is correct
39 Correct 12 ms 24916 KB Output is correct
40 Correct 12 ms 24916 KB Output is correct
41 Correct 13 ms 25172 KB Output is correct
42 Correct 13 ms 25100 KB Output is correct
43 Correct 13 ms 25044 KB Output is correct
44 Correct 13 ms 25096 KB Output is correct
45 Correct 13 ms 25044 KB Output is correct
46 Correct 16 ms 25988 KB Output is correct
47 Correct 14 ms 25980 KB Output is correct
48 Correct 17 ms 25924 KB Output is correct
49 Correct 14 ms 25976 KB Output is correct
50 Correct 16 ms 26012 KB Output is correct
51 Correct 26 ms 33492 KB Output is correct
52 Correct 27 ms 33456 KB Output is correct
53 Execution timed out 4073 ms 33632 KB Time limit exceeded
54 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 24964 KB Output is correct
2 Correct 62 ms 54148 KB Output is correct
3 Correct 61 ms 54148 KB Output is correct
4 Correct 50 ms 53284 KB Output is correct
5 Correct 62 ms 54144 KB Output is correct
6 Correct 59 ms 54720 KB Output is correct
7 Correct 67 ms 56276 KB Output is correct
8 Correct 12 ms 24916 KB Output is correct
9 Correct 13 ms 24960 KB Output is correct
10 Correct 12 ms 24936 KB Output is correct
11 Correct 12 ms 24964 KB Output is correct
12 Correct 13 ms 24964 KB Output is correct
13 Correct 12 ms 24968 KB Output is correct
14 Correct 12 ms 24916 KB Output is correct
15 Correct 13 ms 24916 KB Output is correct
16 Correct 12 ms 24916 KB Output is correct
17 Correct 12 ms 25264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 24964 KB Output is correct
2 Correct 62 ms 54148 KB Output is correct
3 Correct 61 ms 54148 KB Output is correct
4 Correct 50 ms 53284 KB Output is correct
5 Correct 62 ms 54144 KB Output is correct
6 Correct 59 ms 54720 KB Output is correct
7 Correct 67 ms 56276 KB Output is correct
8 Correct 12 ms 24916 KB Output is correct
9 Correct 13 ms 24960 KB Output is correct
10 Correct 12 ms 24936 KB Output is correct
11 Correct 12 ms 24964 KB Output is correct
12 Correct 13 ms 24964 KB Output is correct
13 Correct 12 ms 24968 KB Output is correct
14 Correct 12 ms 24916 KB Output is correct
15 Correct 13 ms 24916 KB Output is correct
16 Correct 12 ms 24916 KB Output is correct
17 Correct 12 ms 25264 KB Output is correct
18 Correct 11 ms 24916 KB Output is correct
19 Correct 11 ms 24964 KB Output is correct
20 Correct 181 ms 60628 KB Output is correct
21 Correct 165 ms 61260 KB Output is correct
22 Correct 172 ms 61428 KB Output is correct
23 Correct 151 ms 58824 KB Output is correct
24 Correct 149 ms 58784 KB Output is correct
25 Correct 172 ms 59616 KB Output is correct
26 Correct 190 ms 61800 KB Output is correct
27 Correct 12 ms 24916 KB Output is correct
28 Correct 12 ms 24916 KB Output is correct
29 Correct 12 ms 24900 KB Output is correct
30 Correct 12 ms 24972 KB Output is correct
31 Correct 13 ms 24972 KB Output is correct
32 Correct 12 ms 24964 KB Output is correct
33 Correct 12 ms 24960 KB Output is correct
34 Correct 12 ms 24916 KB Output is correct
35 Correct 13 ms 24968 KB Output is correct
36 Correct 12 ms 24916 KB Output is correct
37 Correct 11 ms 24904 KB Output is correct
38 Correct 11 ms 24968 KB Output is correct
39 Correct 11 ms 24888 KB Output is correct
40 Correct 13 ms 25012 KB Output is correct
41 Correct 12 ms 24964 KB Output is correct
42 Correct 12 ms 24992 KB Output is correct
43 Correct 12 ms 24964 KB Output is correct
44 Correct 12 ms 24916 KB Output is correct
45 Correct 13 ms 24976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 24964 KB Output is correct
2 Correct 62 ms 54148 KB Output is correct
3 Correct 61 ms 54148 KB Output is correct
4 Correct 50 ms 53284 KB Output is correct
5 Correct 62 ms 54144 KB Output is correct
6 Correct 59 ms 54720 KB Output is correct
7 Correct 67 ms 56276 KB Output is correct
8 Correct 12 ms 24916 KB Output is correct
9 Correct 13 ms 24960 KB Output is correct
10 Correct 12 ms 24936 KB Output is correct
11 Correct 12 ms 24964 KB Output is correct
12 Correct 13 ms 24964 KB Output is correct
13 Correct 12 ms 24968 KB Output is correct
14 Correct 12 ms 24916 KB Output is correct
15 Correct 13 ms 24916 KB Output is correct
16 Correct 12 ms 24916 KB Output is correct
17 Correct 12 ms 25264 KB Output is correct
18 Correct 11 ms 24916 KB Output is correct
19 Correct 11 ms 24964 KB Output is correct
20 Correct 181 ms 60628 KB Output is correct
21 Correct 165 ms 61260 KB Output is correct
22 Correct 172 ms 61428 KB Output is correct
23 Correct 151 ms 58824 KB Output is correct
24 Correct 149 ms 58784 KB Output is correct
25 Correct 172 ms 59616 KB Output is correct
26 Correct 190 ms 61800 KB Output is correct
27 Correct 12 ms 24916 KB Output is correct
28 Correct 12 ms 24916 KB Output is correct
29 Correct 12 ms 24900 KB Output is correct
30 Correct 12 ms 24972 KB Output is correct
31 Correct 13 ms 24972 KB Output is correct
32 Correct 12 ms 24964 KB Output is correct
33 Correct 12 ms 24960 KB Output is correct
34 Correct 12 ms 24916 KB Output is correct
35 Correct 13 ms 24968 KB Output is correct
36 Correct 12 ms 24916 KB Output is correct
37 Correct 11 ms 24904 KB Output is correct
38 Correct 11 ms 24968 KB Output is correct
39 Correct 11 ms 24888 KB Output is correct
40 Correct 13 ms 25012 KB Output is correct
41 Correct 12 ms 24964 KB Output is correct
42 Correct 12 ms 24992 KB Output is correct
43 Correct 12 ms 24964 KB Output is correct
44 Correct 12 ms 24916 KB Output is correct
45 Correct 13 ms 24976 KB Output is correct
46 Correct 11 ms 24960 KB Output is correct
47 Correct 396 ms 62792 KB Output is correct
48 Correct 256 ms 63420 KB Output is correct
49 Correct 263 ms 63396 KB Output is correct
50 Correct 201 ms 61256 KB Output is correct
51 Correct 204 ms 61208 KB Output is correct
52 Correct 1709 ms 62108 KB Output is correct
53 Correct 1931 ms 64848 KB Output is correct
54 Correct 13 ms 25044 KB Output is correct
55 Correct 14 ms 25096 KB Output is correct
56 Correct 12 ms 25120 KB Output is correct
57 Correct 12 ms 25100 KB Output is correct
58 Correct 13 ms 25008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 24964 KB Output is correct
2 Correct 62 ms 54148 KB Output is correct
3 Correct 61 ms 54148 KB Output is correct
4 Correct 50 ms 53284 KB Output is correct
5 Correct 62 ms 54144 KB Output is correct
6 Correct 59 ms 54720 KB Output is correct
7 Correct 67 ms 56276 KB Output is correct
8 Correct 12 ms 24916 KB Output is correct
9 Correct 13 ms 24960 KB Output is correct
10 Correct 12 ms 24936 KB Output is correct
11 Correct 12 ms 24964 KB Output is correct
12 Correct 13 ms 24964 KB Output is correct
13 Correct 12 ms 24968 KB Output is correct
14 Correct 12 ms 24916 KB Output is correct
15 Correct 13 ms 24916 KB Output is correct
16 Correct 12 ms 24916 KB Output is correct
17 Correct 12 ms 25264 KB Output is correct
18 Correct 11 ms 24916 KB Output is correct
19 Correct 11 ms 24964 KB Output is correct
20 Correct 181 ms 60628 KB Output is correct
21 Correct 165 ms 61260 KB Output is correct
22 Correct 172 ms 61428 KB Output is correct
23 Correct 151 ms 58824 KB Output is correct
24 Correct 149 ms 58784 KB Output is correct
25 Correct 172 ms 59616 KB Output is correct
26 Correct 190 ms 61800 KB Output is correct
27 Correct 12 ms 24916 KB Output is correct
28 Correct 12 ms 24916 KB Output is correct
29 Correct 12 ms 24900 KB Output is correct
30 Correct 12 ms 24972 KB Output is correct
31 Correct 13 ms 24972 KB Output is correct
32 Correct 12 ms 24964 KB Output is correct
33 Correct 12 ms 24960 KB Output is correct
34 Correct 12 ms 24916 KB Output is correct
35 Correct 13 ms 24968 KB Output is correct
36 Correct 12 ms 24916 KB Output is correct
37 Correct 11 ms 24904 KB Output is correct
38 Correct 11 ms 24968 KB Output is correct
39 Correct 11 ms 24888 KB Output is correct
40 Correct 13 ms 25012 KB Output is correct
41 Correct 12 ms 24964 KB Output is correct
42 Correct 12 ms 24992 KB Output is correct
43 Correct 12 ms 24964 KB Output is correct
44 Correct 12 ms 24916 KB Output is correct
45 Correct 13 ms 24976 KB Output is correct
46 Correct 11 ms 24960 KB Output is correct
47 Correct 396 ms 62792 KB Output is correct
48 Correct 256 ms 63420 KB Output is correct
49 Correct 263 ms 63396 KB Output is correct
50 Correct 201 ms 61256 KB Output is correct
51 Correct 204 ms 61208 KB Output is correct
52 Correct 1709 ms 62108 KB Output is correct
53 Correct 1931 ms 64848 KB Output is correct
54 Correct 13 ms 25044 KB Output is correct
55 Correct 14 ms 25096 KB Output is correct
56 Correct 12 ms 25120 KB Output is correct
57 Correct 12 ms 25100 KB Output is correct
58 Correct 13 ms 25008 KB Output is correct
59 Execution timed out 4088 ms 63292 KB Time limit exceeded
60 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 24916 KB Output is correct
2 Correct 11 ms 24916 KB Output is correct
3 Correct 11 ms 24916 KB Output is correct
4 Correct 11 ms 24916 KB Output is correct
5 Correct 72 ms 33160 KB Output is correct
6 Correct 25 ms 33192 KB Output is correct
7 Correct 34 ms 33100 KB Output is correct
8 Correct 63 ms 33176 KB Output is correct
9 Correct 683 ms 33200 KB Output is correct
10 Correct 32 ms 33164 KB Output is correct
11 Correct 63 ms 33160 KB Output is correct
12 Correct 681 ms 33204 KB Output is correct
13 Correct 12 ms 24916 KB Output is correct
14 Correct 12 ms 24960 KB Output is correct
15 Correct 12 ms 24864 KB Output is correct
16 Correct 12 ms 24896 KB Output is correct
17 Correct 12 ms 24968 KB Output is correct
18 Correct 12 ms 24916 KB Output is correct
19 Correct 12 ms 24964 KB Output is correct
20 Correct 13 ms 24964 KB Output is correct
21 Correct 13 ms 24916 KB Output is correct
22 Correct 12 ms 24916 KB Output is correct
23 Correct 12 ms 24964 KB Output is correct
24 Correct 12 ms 24916 KB Output is correct
25 Correct 12 ms 24916 KB Output is correct
26 Correct 11 ms 24916 KB Output is correct
27 Correct 12 ms 24916 KB Output is correct
28 Correct 13 ms 24960 KB Output is correct
29 Correct 11 ms 24916 KB Output is correct
30 Correct 12 ms 24880 KB Output is correct
31 Correct 13 ms 24916 KB Output is correct
32 Correct 12 ms 24872 KB Output is correct
33 Correct 12 ms 24964 KB Output is correct
34 Correct 11 ms 24916 KB Output is correct
35 Correct 11 ms 24960 KB Output is correct
36 Correct 13 ms 24984 KB Output is correct
37 Correct 12 ms 24964 KB Output is correct
38 Correct 12 ms 24964 KB Output is correct
39 Correct 12 ms 24916 KB Output is correct
40 Correct 12 ms 24916 KB Output is correct
41 Correct 13 ms 25172 KB Output is correct
42 Correct 13 ms 25100 KB Output is correct
43 Correct 13 ms 25044 KB Output is correct
44 Correct 13 ms 25096 KB Output is correct
45 Correct 13 ms 25044 KB Output is correct
46 Correct 16 ms 25988 KB Output is correct
47 Correct 14 ms 25980 KB Output is correct
48 Correct 17 ms 25924 KB Output is correct
49 Correct 14 ms 25976 KB Output is correct
50 Correct 16 ms 26012 KB Output is correct
51 Correct 26 ms 33492 KB Output is correct
52 Correct 27 ms 33456 KB Output is correct
53 Execution timed out 4073 ms 33632 KB Time limit exceeded
54 Halted 0 ms 0 KB -