답안 #955465

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
955465 2024-03-30T13:50:33 Z LCJLY Council (JOI23_council) C++14
62 / 100
494 ms 106060 KB
#include <bits/stdc++.h>
using namespace std;
 
#define int long long 
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << "  " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << "  " << j << " " << #i << "  " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<int,int>pii;
typedef pair<pii,pii>pi2;
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int n,m;
int arr[300005];
int cnt[25];

vector<int>sub[150005];

pi2 f(pi2 a, int b, int c){
	if(b>=a.first.first){
		if(a.first.second==c){
			a.first={b,c};
		}
		else{
			a.second=a.first;
			a.first={b,c};
		}
	}
	else if(b>=a.second.first){
		if(a.first.second!=c) a.second={b,c};
	}
	return a;
}

pi2 memo[25][150005];
bool vis[25][150005];

void out(int x){
	for(int y=0;y<m;y++){
		cout << ((x&(1<<y))>0);
	}
	cout << endl;
}

pi2 dp(int index, int mask){	
	if(index>=m){
		pi2 cur={{0,0},{0,0}};
		int num=__builtin_popcount(mask);
		if(sub[mask].size()==1){
			cur.first={num,sub[mask][0]};
		}
		else if(sub[mask].size()>1){
			cur.first={num,sub[mask][0]};
			cur.second={num,sub[mask][1]};
		}
		//if(cur.first.first>=4){
			//show2(a,cur.first.first,b,cur.first.second);
			//show2(c,cur.second.first,d,cur.second.second);
			//cout <<  "mask ";
			//out(mask);
		//}
		return cur;
		
	}
	if(vis[index][mask]) return memo[index][mask];
	pi2 ans=dp(index+1,mask);
	if(mask&(1<<index)){
		pi2 hold=dp(index+1,mask^(1<<index));
		ans=f(ans,hold.first.first,hold.first.second);
		ans=f(ans,hold.second.first,hold.second.second);
	}	
	vis[index][mask]=true;
	return memo[index][mask]=ans;
}

void dfs(int index, int mask){
	if(mask==0) return;
	if(sub[mask].size()>=2) return;
	if(sub[mask].size()>0&&sub[mask][0]==index) return;
	if(sub[mask].size()>1&&sub[mask][1]==index) return;
	sub[mask].push_back(index);
	for(int x=0;x<m;x++){
		if(mask&(1<<x)){
			dfs(index,mask^(1<<x));
		}
	}
}

void solve(){
	cin >> n >> m;
	
	int temp;
	for(int x=0;x<n;x++){
		int inv=0;
		for(int y=0;y<m;y++){
			cin >> temp;
			arr[x]+=temp*(1<<y);
			cnt[y]+=temp;
			inv+=(1-temp)*(1<<y);
		}
		dfs(x,inv);
	}
	
	for(int x=0;x<n;x++){
		for(int y=0;y<m;y++){
			if(arr[x]&(1<<y)) cnt[y]--;
		}
		
		int crit=n/2;
		int safe=0;
		int hold=0;
		for(int y=0;y<m;y++){
			if(cnt[y]>crit) safe++; 
			if(cnt[y]==crit) hold+=(1<<y);
		}
		
		//show2(x,x,safe,safe);
		//out(hold);
		
		pi2 take=dp(0,hold);
		//show2(aa,take.first.first,bb,take.first.second);
		//show2(cc,take.second.first,dd,take.second.second);
		if(take.first.second==x){
			safe+=take.second.first;
		}
		else safe+=take.first.first;
		
		for(int y=0;y<m;y++){
			if(arr[x]&(1<<y)) cnt[y]++;
		}
		
		cout << safe << "\n";
	}		
	
	
}
 
int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin >> t;
	while(t--){
		solve();
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12636 KB Output is correct
2 Correct 5 ms 33116 KB Output is correct
3 Correct 2 ms 14684 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Runtime error 12 ms 13088 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12636 KB Output is correct
2 Correct 5 ms 33116 KB Output is correct
3 Correct 2 ms 14684 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Runtime error 12 ms 13088 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 45 ms 12884 KB Output is correct
3 Correct 42 ms 12896 KB Output is correct
4 Correct 32 ms 10840 KB Output is correct
5 Correct 53 ms 13068 KB Output is correct
6 Correct 31 ms 10832 KB Output is correct
7 Correct 47 ms 12888 KB Output is correct
8 Correct 2 ms 8540 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 10840 KB Output is correct
12 Correct 2 ms 10588 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
16 Correct 2 ms 10584 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 45 ms 12884 KB Output is correct
3 Correct 42 ms 12896 KB Output is correct
4 Correct 32 ms 10840 KB Output is correct
5 Correct 53 ms 13068 KB Output is correct
6 Correct 31 ms 10832 KB Output is correct
7 Correct 47 ms 12888 KB Output is correct
8 Correct 2 ms 8540 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 10840 KB Output is correct
12 Correct 2 ms 10588 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
16 Correct 2 ms 10584 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 ms 12636 KB Output is correct
19 Correct 2 ms 14684 KB Output is correct
20 Correct 163 ms 31360 KB Output is correct
21 Correct 146 ms 27120 KB Output is correct
22 Correct 145 ms 27216 KB Output is correct
23 Correct 147 ms 29596 KB Output is correct
24 Correct 130 ms 29264 KB Output is correct
25 Correct 176 ms 29268 KB Output is correct
26 Correct 183 ms 31468 KB Output is correct
27 Correct 4 ms 29020 KB Output is correct
28 Correct 2 ms 12636 KB Output is correct
29 Correct 2 ms 14684 KB Output is correct
30 Correct 3 ms 16732 KB Output is correct
31 Correct 3 ms 18780 KB Output is correct
32 Correct 3 ms 20828 KB Output is correct
33 Correct 4 ms 22872 KB Output is correct
34 Correct 4 ms 24924 KB Output is correct
35 Correct 4 ms 26968 KB Output is correct
36 Correct 4 ms 26972 KB Output is correct
37 Correct 2 ms 12636 KB Output is correct
38 Correct 2 ms 14684 KB Output is correct
39 Correct 2 ms 16732 KB Output is correct
40 Correct 3 ms 18780 KB Output is correct
41 Correct 3 ms 20828 KB Output is correct
42 Correct 3 ms 22872 KB Output is correct
43 Correct 4 ms 24924 KB Output is correct
44 Correct 4 ms 29020 KB Output is correct
45 Correct 5 ms 29276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 45 ms 12884 KB Output is correct
3 Correct 42 ms 12896 KB Output is correct
4 Correct 32 ms 10840 KB Output is correct
5 Correct 53 ms 13068 KB Output is correct
6 Correct 31 ms 10832 KB Output is correct
7 Correct 47 ms 12888 KB Output is correct
8 Correct 2 ms 8540 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 10840 KB Output is correct
12 Correct 2 ms 10588 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
16 Correct 2 ms 10584 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 ms 12636 KB Output is correct
19 Correct 2 ms 14684 KB Output is correct
20 Correct 163 ms 31360 KB Output is correct
21 Correct 146 ms 27120 KB Output is correct
22 Correct 145 ms 27216 KB Output is correct
23 Correct 147 ms 29596 KB Output is correct
24 Correct 130 ms 29264 KB Output is correct
25 Correct 176 ms 29268 KB Output is correct
26 Correct 183 ms 31468 KB Output is correct
27 Correct 4 ms 29020 KB Output is correct
28 Correct 2 ms 12636 KB Output is correct
29 Correct 2 ms 14684 KB Output is correct
30 Correct 3 ms 16732 KB Output is correct
31 Correct 3 ms 18780 KB Output is correct
32 Correct 3 ms 20828 KB Output is correct
33 Correct 4 ms 22872 KB Output is correct
34 Correct 4 ms 24924 KB Output is correct
35 Correct 4 ms 26968 KB Output is correct
36 Correct 4 ms 26972 KB Output is correct
37 Correct 2 ms 12636 KB Output is correct
38 Correct 2 ms 14684 KB Output is correct
39 Correct 2 ms 16732 KB Output is correct
40 Correct 3 ms 18780 KB Output is correct
41 Correct 3 ms 20828 KB Output is correct
42 Correct 3 ms 22872 KB Output is correct
43 Correct 4 ms 24924 KB Output is correct
44 Correct 4 ms 29020 KB Output is correct
45 Correct 5 ms 29276 KB Output is correct
46 Correct 5 ms 33116 KB Output is correct
47 Correct 256 ms 44452 KB Output is correct
48 Correct 229 ms 40016 KB Output is correct
49 Correct 242 ms 40168 KB Output is correct
50 Correct 182 ms 37832 KB Output is correct
51 Correct 171 ms 38108 KB Output is correct
52 Correct 236 ms 37904 KB Output is correct
53 Correct 272 ms 44532 KB Output is correct
54 Correct 9 ms 41816 KB Output is correct
55 Correct 5 ms 37468 KB Output is correct
56 Correct 6 ms 37468 KB Output is correct
57 Correct 6 ms 39516 KB Output is correct
58 Correct 6 ms 41820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 45 ms 12884 KB Output is correct
3 Correct 42 ms 12896 KB Output is correct
4 Correct 32 ms 10840 KB Output is correct
5 Correct 53 ms 13068 KB Output is correct
6 Correct 31 ms 10832 KB Output is correct
7 Correct 47 ms 12888 KB Output is correct
8 Correct 2 ms 8540 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 10840 KB Output is correct
12 Correct 2 ms 10588 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
16 Correct 2 ms 10584 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 ms 12636 KB Output is correct
19 Correct 2 ms 14684 KB Output is correct
20 Correct 163 ms 31360 KB Output is correct
21 Correct 146 ms 27120 KB Output is correct
22 Correct 145 ms 27216 KB Output is correct
23 Correct 147 ms 29596 KB Output is correct
24 Correct 130 ms 29264 KB Output is correct
25 Correct 176 ms 29268 KB Output is correct
26 Correct 183 ms 31468 KB Output is correct
27 Correct 4 ms 29020 KB Output is correct
28 Correct 2 ms 12636 KB Output is correct
29 Correct 2 ms 14684 KB Output is correct
30 Correct 3 ms 16732 KB Output is correct
31 Correct 3 ms 18780 KB Output is correct
32 Correct 3 ms 20828 KB Output is correct
33 Correct 4 ms 22872 KB Output is correct
34 Correct 4 ms 24924 KB Output is correct
35 Correct 4 ms 26968 KB Output is correct
36 Correct 4 ms 26972 KB Output is correct
37 Correct 2 ms 12636 KB Output is correct
38 Correct 2 ms 14684 KB Output is correct
39 Correct 2 ms 16732 KB Output is correct
40 Correct 3 ms 18780 KB Output is correct
41 Correct 3 ms 20828 KB Output is correct
42 Correct 3 ms 22872 KB Output is correct
43 Correct 4 ms 24924 KB Output is correct
44 Correct 4 ms 29020 KB Output is correct
45 Correct 5 ms 29276 KB Output is correct
46 Correct 5 ms 33116 KB Output is correct
47 Correct 256 ms 44452 KB Output is correct
48 Correct 229 ms 40016 KB Output is correct
49 Correct 242 ms 40168 KB Output is correct
50 Correct 182 ms 37832 KB Output is correct
51 Correct 171 ms 38108 KB Output is correct
52 Correct 236 ms 37904 KB Output is correct
53 Correct 272 ms 44532 KB Output is correct
54 Correct 9 ms 41816 KB Output is correct
55 Correct 5 ms 37468 KB Output is correct
56 Correct 6 ms 37468 KB Output is correct
57 Correct 6 ms 39516 KB Output is correct
58 Correct 6 ms 41820 KB Output is correct
59 Correct 279 ms 43088 KB Output is correct
60 Correct 289 ms 97360 KB Output is correct
61 Correct 299 ms 97992 KB Output is correct
62 Correct 294 ms 98116 KB Output is correct
63 Correct 334 ms 86904 KB Output is correct
64 Correct 408 ms 104824 KB Output is correct
65 Correct 409 ms 104788 KB Output is correct
66 Correct 229 ms 51924 KB Output is correct
67 Correct 238 ms 55796 KB Output is correct
68 Correct 326 ms 55704 KB Output is correct
69 Correct 494 ms 106060 KB Output is correct
70 Correct 46 ms 74832 KB Output is correct
71 Correct 9 ms 66652 KB Output is correct
72 Correct 9 ms 58460 KB Output is correct
73 Correct 13 ms 87388 KB Output is correct
74 Correct 17 ms 88552 KB Output is correct
75 Correct 99 ms 93016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12636 KB Output is correct
2 Correct 5 ms 33116 KB Output is correct
3 Correct 2 ms 14684 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Runtime error 12 ms 13088 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -