結果
| 問題 | No.1669 パズル作成 | 
| コンテスト | |
| ユーザー |  沙耶花 | 
| 提出日時 | 2021-02-27 14:29:41 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                TLE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 766 bytes | 
| コンパイル時間 | 4,101 ms | 
| コンパイル使用メモリ | 254,592 KB | 
| 最終ジャッジ日時 | 2025-01-19 07:53:44 | 
| ジャッジサーバーID (参考情報) | judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 9 WA * 1 TLE * 19 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:20:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 |                 scanf("%d %d",&r,&c);
      |                 ~~~~~^~~~~~~~~~~~~~~
            
            ソースコード
#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;
}
            
            
            
        