結果
| 問題 |
No.1479 Matrix Eraser
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-04-24 05:31:07 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,294 bytes |
| コンパイル時間 | 849 ms |
| コンパイル使用メモリ | 85,112 KB |
| 実行使用メモリ | 7,808 KB |
| 最終ジャッジ日時 | 2024-07-04 08:59:42 |
| 合計ジャッジ時間 | 37,197 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 38 TLE * 1 |
コンパイルメッセージ
a.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
ソースコード
#line 1 "a.cpp"
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#line 3 "/home/kotatsugame/library/graph/bimatch.cpp"
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(match[v]<0&&dfs(v))ans++,flag=true;
}
return ans;
}
};
#line 6 "a.cpp"
int N,M;
main()
{
cin>>N>>M;
vector<pair<int,pair<int,int> > >A(N*M);
for(int i=0;i<N;i++)for(int j=0;j<M;j++)
{
cin>>A[i*M+j].first;
A[i*M+j].second=make_pair(i,j);
}
sort(A.begin(),A.end());
int ans=0;
for(int i=0;i<A.size();)
{
if(A[i].first==0)
{
i++;
continue;
}
int j=i;
bimatch P(N+M);
while(j<A.size()&&A[i].first==A[j].first)
{
P.add_edge(A[j].second.first,A[j].second.second+N);
j++;
}
i=j;
ans+=P.count();
}
cout<<ans<<endl;
}