結果
| 問題 |
No.1669 パズル作成
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2021-02-27 14:21:15 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,215 bytes |
| コンパイル時間 | 3,897 ms |
| コンパイル使用メモリ | 254,344 KB |
| 最終ジャッジ日時 | 2025-01-19 07:52:07 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 3 |
| other | AC * 6 WA * 23 |
コンパイルメッセージ
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;
{
vector<int> dp(N+1,Inf);
dp[0] = 0;
rep(i,x.size()){
vector<int> ndp(N+1,Inf);
rep(j,N+1){
if(dp[j]==Inf)continue;
ndp[j] = min(ndp[j],dp[j]);
ndp[j+x[i]] = min(ndp[j+x[i]],dp[j] + y[i]);
}
}
rep(i,N+1){
if(dp[i]==Inf)continue;
ans = min(ans,i*dp[i] + (N-i) * (N-dp[i]) - M);
}
}
{
vector<int> dp(N+1,-Inf);
dp[0] = 0;
rep(i,x.size()){
vector<int> ndp(N+1,-Inf);
rep(j,N+1){
if(dp[j]==-Inf)continue;
ndp[j] = max(ndp[j],dp[j]);
ndp[j+x[i]] = max(ndp[j+x[i]],dp[j] + y[i]);
}
}
rep(i,N+1){
if(dp[i]==-Inf)continue;
ans = min(ans,i*dp[i] + (N-i) * (N-dp[i]) - M);
}
}
cout<<ans<<endl;
return 0;
}
沙耶花