結果

問題 No.1669 パズル作成
ユーザー 沙耶花沙耶花
提出日時 2021-02-27 14:29:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 766 bytes
コンパイル時間 4,833 ms
コンパイル使用メモリ 263,060 KB
実行使用メモリ 17,336 KB
最終ジャッジ日時 2023-08-21 18:47:53
合計ジャッジ時間 10,686 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
17,120 KB
testcase_01 AC 38 ms
12,548 KB
testcase_02 AC 37 ms
12,672 KB
testcase_03 AC 724 ms
12,612 KB
testcase_04 AC 319 ms
12,640 KB
testcase_05 AC 866 ms
12,824 KB
testcase_06 AC 50 ms
12,596 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000



int main(){
	
	int N,M;
	cin>>N>>M;
	
	dsu D(2*N);
	rep(i,M){
		int r,c;
		scanf("%d %d",&r,&c);
		r--;c--;
		
		D.merge(r,N+c);
	}
	
	auto g = D.groups();
	vector<int> x(g.size(),0),y(g.size(),0);
	
	rep(i,g.size()){
		rep(j,g[i].size()){
			if(g[i][j]<N)x[i]++;
			else y[i]++;
		}
	}
	
	int ans = Inf;
	
	bitset<25000001> B;
	B[0] = 1;
	
	rep(i,x.size()){
		B |= B << (x[i]*5000 + y[i]);
	}
	
	rep(i,B.size()){
		int x = i%5000,y = i/5000;
		if(B[i]){
			ans = min(ans,x*y + (N-x)*(N-y) - M);
		}
	}
	
	
	

	
	cout<<ans<<endl;
	
	
    return 0;
}
0