結果

問題 No.1479 Matrix Eraser
ユーザー kotatsugame
提出日時 2025-01-26 01:06:04
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,274 bytes
コンパイル時間 938 ms
コンパイル使用メモリ 81,940 KB
実行使用メモリ 7,664 KB
最終ジャッジ日時 2025-01-26 01:06:54
合計ジャッジ時間 42,641 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 37 TLE * 2
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:69:29: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   69 |                         auto[u,v]=E[i++].second;
      |                             ^

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<cassert>
using namespace std;
#include<algorithm>
#include<vector>
struct bimatch{
	int n;
	vector<vector<int> >G;
	vector<int>match;
	vector<bool>used;
	bimatch(int _n=0):n(_n),G(n),match(n),used(n){}
	void add_edge(int u,int v)
	{
		G[u].push_back(v);
		G[v].push_back(u);
	}
	bool dfs(int v)
	{
		used[v]=true;
		for(int u:G[v])
		{
			int w=match[u];
			if(w<0||!used[w]&&dfs(w))
			{
				match[v]=u;
				match[u]=v;
				return true;
			}
		}
		return false;
	}
	int count()
	{
		int ans=0;
		bool flag=true;
		fill(match.begin(),match.end(),-1);
		while(flag)
		{
			flag=false;
			fill(used.begin(),used.end(),false);
			for(int v=0;v<n;v++)if(!used[v]&&match[v]<0&&dfs(v))ans++,flag=true;
		}
		return ans;
	}
};
int H,W;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>H>>W;
	vector<pair<int,pair<int,int> > >E;
	E.reserve(H*W);
	for(int i=0;i<H;i++)for(int j=0;j<W;j++)
	{
		int a;cin>>a;
		if(a)E.push_back(make_pair(a,make_pair(i,j)));
	}
	sort(E.begin(),E.end());
	int ans=0;
	for(int i=0;i<E.size();)
	{
		bimatch P(H+W);
		int a=E[i].first;
		while(i<E.size()&&E[i].first==a)
		{
			auto[u,v]=E[i++].second;
			P.add_edge(u,v+H);
		}
		ans+=P.count();
	}
	cout<<ans<<endl;
}
0