結果

問題 No.421 しろくろチョコレート
ユーザー vjudge1
提出日時 2024-12-22 16:55:24
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
RE  
実行時間 -
コード長 1,230 bytes
コンパイル時間 3,283 ms
コンパイル使用メモリ 160,636 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-22 16:55:43
合計ジャッジ時間 8,476 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26 WA * 1 RE * 38
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
vector<int> z[maxn];
int n1, n2, m, ans, N, M;
void add_edge(int s,int e)
{
z[s].push_back(e);
}
bool vis[maxn];
char choco[105][105];
int result[maxn];
bool dfs(int i)
{
for (int k=0;k<z[i].size();k++)
{
int j = z[i][k];
if (!vis[j])
{
vis[j] = true;
if (!result[j] || dfs(result[j]))
{
result[j] = i;
return true;
}
}
}
return false;
}
int zb(int x, int y)
{
return M*(x-1)+y;
}
int main()
{
cin >> N >> M;
for (int i = 1;i <= N;i++)
{
for (int j = 1;j <= M;j++)
{
cin >> choco[i][j];
}
}
for (int i = 1;i <= N;i++)
{
for (int j = 1;j <= M;j++)
{
if(choco[i][j] == 'b')
{
n1++;
if(choco[i][j+1]=='w')
{
add_edge(n1, zb(i, j+1));
}
if(choco[i+1][j]=='w')
{
add_edge(n1, zb(i+1, j));
}
if(choco[i][j-1]=='w')
{
add_edge(n1, zb(i, j-1));
}
if(choco[i-1][j]=='w')
{
add_edge(n1, zb(i-1, j));
}
}
if(choco[i][j] == 'w') n2++;
}
}
for (int i=1;i<=n1;i++)
{
memset(vis,false,sizeof(vis));
if (dfs(i)) ans++;
}
if(n1 > n2) cout << ans*100 + (n2-ans)*10 + n1-n2;
if(n1 <= n2) cout << ans*100 + (n1-ans)*10 + n2-n1;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0