提出 #35889962


ソースコード 拡げる

#include<bits/stdc++.h>
using namespace std;

const int s = 100010;
const int t = 100011;
const int inf = 1e9;

struct edge
{
    int val;
    int to,nxt;
};

edge e[1000100];
int head[100100],cnt=1;
int dep[100100];
int r[310][310],c[310][310];
int ccnt,rcnt;
char a[310][310];

void addEdge(int x, int y, int z)
{
    e[++cnt].to=y; e[cnt].val=z;
    e[cnt].nxt=head[x]; head[x]=cnt;
    e[++cnt].to=x; e[cnt].val=0;
    e[cnt].nxt=head[y]; head[y]=cnt;
}
bool bfs()
{
    queue<int> q;
    memset(dep, 0, sizeof(dep));

    q.push(s); dep[s]=1;
    while(q.size())
    {
        int x=q.front(); q.pop();
        for(int i=head[x]; i; i=e[i].nxt)
        {
            int y=e[i].to;
            if(!dep[y]&&e[i].val)
            {
                dep[y]=dep[x]+1;
                q.push(y);
            }
        }
    }
    return dep[t];
}
int dfs(int x, int want)
{
    if(x==t) return want;
    int get=0,f;
    for(int i=head[x]; i; i=e[i].nxt)
    {
        int y=e[i].to;
        if(dep[y]==dep[x]+1&&e[i].val)
        {
            f=dfs(y, min(want, e[i].val));
            if(!f) dep[y]=0;
            want-=f; get+=f;
            e[i].val-=f; e[i^1].val+=f;
            if(!want) break;
        }
    }
    return get;
}
int Dinic()
{
    int flow=0,f;
    while(bfs()) while(f=dfs(s, inf)) flow+=f;
    return flow;
}
int main()
{
    int n,m;
    int i,j;

    cin>>n>>m;
    for(i=1; i<=n; i++)
    scanf("%s", a[i]+1);

    for(i=1; i<=n; i++)
    for(j=1; j<=m; j++)
    if(a[i][j]=='.')
    {
        if(c[i][j-1]) c[i][j]=c[i][j-1];
        else c[i][j]=++ccnt;
        if(r[i-1][j]) r[i][j]=r[i-1][j];
        else r[i][j]=++rcnt;
    }

    for(i=1; i<=n; i++)
    for(j=1; j<=m; j++)
    if(a[i][j]=='.')
    addEdge(r[i][j], c[i][j]+rcnt, 1);

    for(i=1; i<=rcnt; i++)
    addEdge(s, i, 1);
    for(i=1; i<=ccnt; i++)
    addEdge(i+rcnt, t, 1);

    cout<<Dinic();
    return 0;
}

提出情報

提出日時
問題 G - Security Camera 3
ユーザ LingChen
言語 C++ (GCC 9.2.1)
得点 600
コード長 2011 Byte
結果 AC
実行時間 102 ms
メモリ 7796 KiB

コンパイルエラー

./Main.cpp: In function ‘int Dinic()’:
./Main.cpp:70:25: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   70 |     while(bfs()) while(f=dfs(s, inf)) flow+=f;
      |                        ~^~~~~~~~~~~~
./Main.cpp: In function ‘int main()’:
./Main.cpp:80:10: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   80 |     scanf("%s", a[i]+1);
      |     ~~~~~^~~~~~~~~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果
AC × 3
AC × 31
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, sample_01.txt, sample_02.txt, sample_03.txt
ケース名 結果 実行時間 メモリ
random_01.txt AC 12 ms 5104 KiB
random_02.txt AC 18 ms 5652 KiB
random_03.txt AC 11 ms 5384 KiB
random_04.txt AC 8 ms 4640 KiB
random_05.txt AC 18 ms 5692 KiB
random_06.txt AC 6 ms 4480 KiB
random_07.txt AC 30 ms 5564 KiB
random_08.txt AC 15 ms 5584 KiB
random_09.txt AC 102 ms 7172 KiB
random_10.txt AC 52 ms 5948 KiB
random_11.txt AC 46 ms 6272 KiB
random_12.txt AC 24 ms 5136 KiB
random_13.txt AC 36 ms 7472 KiB
random_14.txt AC 4 ms 4040 KiB
random_15.txt AC 14 ms 5764 KiB
random_16.txt AC 3 ms 4552 KiB
random_17.txt AC 19 ms 7224 KiB
random_18.txt AC 3 ms 3956 KiB
random_19.txt AC 6 ms 4756 KiB
random_20.txt AC 3 ms 3920 KiB
random_21.txt AC 11 ms 7796 KiB
random_22.txt AC 12 ms 7560 KiB
random_23.txt AC 11 ms 7592 KiB
random_24.txt AC 10 ms 7376 KiB
random_25.txt AC 15 ms 7084 KiB
random_26.txt AC 11 ms 6988 KiB
random_27.txt AC 11 ms 5740 KiB
random_28.txt AC 4 ms 4044 KiB
sample_01.txt AC 5 ms 4032 KiB
sample_02.txt AC 4 ms 3888 KiB
sample_03.txt AC 4 ms 4124 KiB