Submission #44476100


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

#define de(x) cout<<#x<<"="<<x<<endl

using ll = long long;
using d = long double;

ll n,m,id[44],msk[44];
d a[44],b[44];
int x[100005],y[100005];
vector<int> pos,neg;
bool f[100005];
d dff[44],dfp[44],dfn[44];
d dp[44][1<<20];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	cout<<fixed<<setprecision(10);
	cin>>n>>m;
	for (int i=0; i<n; i++){
		cin>>a[i]>>b[i];
	}
	for (int i=0; i<m; i++){
		cin>>x[i]>>y[i];
		x[i]--;
		y[i]--;
		if (x[i]==y[i] && a[x[i]]<b[x[i]]){
			swap(a[x[i]],b[x[i]]);
		}
	}
	d ans=0.;
	for (int i=0; i<n; i++){
		ans+=a[i];
		d df=(a[i]+b[i])/2.-a[i];
//		cout<<df<<endl;
		if (df>=0){
			id[i]=pos.size();
			dfp[id[i]]=df;
			pos.push_back(df);
			f[i]=0;
		}
		else{
			id[i]=neg.size();
			dfn[id[i]]=df;
			neg.push_back(df);
			f[i]=1;
		}
		dff[i]=df;
	}
//	cout<<ans<<endl;
	for (int i=0; i<m; i++){
		if (f[x[i]]!=f[y[i]]){
			if (f[x[i]]==0){
				swap(x[i],y[i]);
			}
			msk[id[x[i]]]|=1ll<<id[y[i]];
//			cout<<id[x[i]]<<": "<<msk[id[x[i]]]<<endl;
		}
		else{
			if (f[x[i]]==0){
				ans+=dff[x[i]]+dff[y[i]];
				dff[x[i]]=dff[y[i]]=0;
				dfp[id[x[i]]]=dfp[id[y[i]]]=0;
				pos[id[x[i]]]=pos[id[y[i]]]=0;
			}
		}
	}
	int ps=pos.size(),ns=neg.size();
//	cout<<ps<<","<<ns<<endl;
//	cout<<ans<<endl;
	if (ps>=ns){
		d res=0.;
		for (int i=0; i<(1<<ns); i++){
			d cur=0.;
			ll mk=0;
			for (int j=0; j<ns; j++){
				if ((i>>j)&1){
					cur+=dfn[j];
					mk|=msk[j];
				}
			}
			for (int j=0; j<ps; j++){
				if ((mk>>j)&1){
					cur+=dfp[j];
				}
			}
//			cout<<i<<": "<<cur<<endl;
			res=max(res,cur);
		}
		cout<<ans+res<<endl;
	}
	else{
		for (int i=0; i<=ns; i++){
			for (int j=0; j<(1<<ps); j++){
				dp[i][j]=-1000000000.;
			}
		}
		dp[0][0]=0.;
		for (int i=0; i<ns; i++){
			for (int j=0; j<(1<<ps); j++){
				dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
//				cout<<i+1<<","<<(j)<<": "<< dp[i+1][j]<<endl;
				dp[i+1][j|msk[i]]=max(dp[i+1][j|msk[i]],dp[i][j]+dfn[i]);
//				cout<<i+1<<","<<(j|msk[i])<<": "<< dp[i+1][j|msk[i]]<<endl;
			} 
		}
		d res=0.;
		for (int i=0; i<(1<<ps); i++){
			d cur=dp[ns][i];
			for (int j=0; j<ps; j++){
				if ((i>>j)&1){
					cur+=dfp[j];
				}
			}
//			cout<<i<<": "<<cur<<endl;
			res=max(res,cur);
		}
		cout<<ans+res<<endl;
	}
	return 0;
}

// don't waste time!!!

Submission Info

Submission Time
Task F - Flip Machines
User SFlyer
Language C++ (GCC 9.2.1)
Score 625
Code Size 2440 Byte
Status AC
Exec Time 226 ms
Memory 176696 KiB

Judge Result

Set Name Sample All AfterContest
Score / Max Score 0 / 0 625 / 625 0 / 0
Status
AC × 3
AC × 68
AC × 4
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 02_random2_06.txt, 02_random2_07.txt, 02_random2_08.txt, 02_random2_09.txt, 02_random2_10.txt, 02_random2_11.txt, 02_random2_12.txt, 02_random2_13.txt, 02_random2_14.txt, 02_random2_15.txt, 02_random2_16.txt, 02_random2_17.txt, 02_random2_18.txt, 02_random2_19.txt, 02_random2_20.txt, 03_random3_00.txt, 03_random3_01.txt, 03_random3_02.txt, 03_random3_03.txt, 03_random3_04.txt, 03_random3_05.txt, 03_random3_06.txt, 03_random3_07.txt, 03_random3_08.txt, 04_random4_00.txt, 04_random4_01.txt, 04_random4_02.txt, 04_random4_03.txt, 04_random4_04.txt, 04_random4_05.txt, 04_random4_06.txt, 04_random4_07.txt, 04_random4_08.txt, 05_misc_00.txt, 05_misc_01.txt, 05_misc_02.txt, 05_misc_03.txt, 05_misc_04.txt
AfterContest after_contest_00.txt, after_contest_01.txt, after_contest_02.txt, after_contest_03.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 6 ms 3688 KiB
00_sample_01.txt AC 3 ms 3776 KiB
00_sample_02.txt AC 2 ms 3848 KiB
01_random_00.txt AC 22 ms 4520 KiB
01_random_01.txt AC 22 ms 4572 KiB
01_random_02.txt AC 19 ms 4568 KiB
01_random_03.txt AC 18 ms 4464 KiB
01_random_04.txt AC 18 ms 4516 KiB
01_random_05.txt AC 26 ms 4548 KiB
01_random_06.txt AC 18 ms 4572 KiB
01_random_07.txt AC 23 ms 4516 KiB
01_random_08.txt AC 23 ms 4516 KiB
01_random_09.txt AC 226 ms 176696 KiB
01_random_10.txt AC 105 ms 4628 KiB
01_random_11.txt AC 107 ms 4468 KiB
01_random_12.txt AC 25 ms 5008 KiB
01_random_13.txt AC 18 ms 5152 KiB
01_random_14.txt AC 20 ms 5000 KiB
01_random_15.txt AC 18 ms 4680 KiB
01_random_16.txt AC 18 ms 4764 KiB
01_random_17.txt AC 18 ms 4764 KiB
01_random_18.txt AC 17 ms 4780 KiB
01_random_19.txt AC 18 ms 4772 KiB
01_random_20.txt AC 18 ms 4728 KiB
02_random2_00.txt AC 20 ms 4464 KiB
02_random2_01.txt AC 20 ms 4612 KiB
02_random2_02.txt AC 18 ms 4632 KiB
02_random2_03.txt AC 17 ms 4476 KiB
02_random2_04.txt AC 26 ms 4464 KiB
02_random2_05.txt AC 19 ms 4520 KiB
02_random2_06.txt AC 18 ms 4472 KiB
02_random2_07.txt AC 18 ms 4540 KiB
02_random2_08.txt AC 18 ms 4520 KiB
02_random2_09.txt AC 106 ms 4588 KiB
02_random2_10.txt AC 105 ms 4544 KiB
02_random2_11.txt AC 105 ms 4564 KiB
02_random2_12.txt AC 19 ms 4828 KiB
02_random2_13.txt AC 19 ms 5092 KiB
02_random2_14.txt AC 24 ms 5140 KiB
02_random2_15.txt AC 20 ms 4600 KiB
02_random2_16.txt AC 19 ms 4728 KiB
02_random2_17.txt AC 18 ms 4680 KiB
02_random2_18.txt AC 17 ms 4700 KiB
02_random2_19.txt AC 21 ms 4700 KiB
02_random2_20.txt AC 17 ms 4680 KiB
03_random3_00.txt AC 21 ms 4592 KiB
03_random3_01.txt AC 18 ms 4620 KiB
03_random3_02.txt AC 20 ms 4456 KiB
03_random3_03.txt AC 106 ms 4456 KiB
03_random3_04.txt AC 223 ms 176652 KiB
03_random3_05.txt AC 108 ms 4576 KiB
03_random3_06.txt AC 18 ms 4836 KiB
03_random3_07.txt AC 18 ms 5156 KiB
03_random3_08.txt AC 18 ms 5092 KiB
04_random4_00.txt AC 18 ms 4536 KiB
04_random4_01.txt AC 18 ms 4628 KiB
04_random4_02.txt AC 22 ms 4548 KiB
04_random4_03.txt AC 226 ms 176688 KiB
04_random4_04.txt AC 223 ms 176652 KiB
04_random4_05.txt AC 224 ms 176628 KiB
04_random4_06.txt AC 18 ms 4840 KiB
04_random4_07.txt AC 18 ms 4976 KiB
04_random4_08.txt AC 18 ms 4832 KiB
05_misc_00.txt AC 2 ms 3744 KiB
05_misc_01.txt AC 18 ms 4808 KiB
05_misc_02.txt AC 28 ms 4464 KiB
05_misc_03.txt AC 17 ms 4696 KiB
05_misc_04.txt AC 18 ms 4696 KiB
after_contest_00.txt AC 17 ms 4456 KiB
after_contest_01.txt AC 18 ms 4544 KiB
after_contest_02.txt AC 19 ms 4540 KiB
after_contest_03.txt AC 18 ms 4512 KiB