結果
| 問題 |
No.421 しろくろチョコレート
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-03-02 20:09:46 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 1,232 bytes |
| コンパイル時間 | 971 ms |
| コンパイル使用メモリ | 78,464 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-23 07:24:50 |
| 合計ジャッジ時間 | 2,465 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 65 |
コンパイルメッセージ
main.cpp:50:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
50 | main()
| ^~~~
ソースコード
#include<iostream>
#include<algorithm>
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(match[v]<0&&dfs(v))ans++,flag=true;
}
return ans;
}
};
int N,M;
string s[50];
int d[4]={1,0,-1};
main()
{
cin>>N>>M;
for(int i=0;i<N;i++)cin>>s[i];
bimatch P(N*M);
int b=0,w=0;
for(int i=0;i<N;i++)for(int j=0;j<M;j++)
{
int x=i,y=j;
if(s[x][y]=='.')continue;
if(s[x][y]=='b')b++;
else w++;
for(int r=0;r<4;r++)
{
int tx=x+d[r],ty=y+d[r^1];
if(tx<0||ty<0||tx>=N||ty>=M||s[tx][ty]=='.')continue;
P.add_edge(x*M+y,tx*M+ty);
}
}
int ans=P.count();
b-=ans;
w-=ans;
cout<<ans*100+min(b,w)*10+(w+b-2*min(b,w))<<endl;
}