QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#376074#8507. Clever Cell Choicesinstallb#WA 0ms3852kbC++202.8kb2024-04-03 20:24:162024-04-03 20:24:17

Judging History

你现在查看的是最新测评结果

  • [2024-04-03 20:24:17]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3852kb
  • [2024-04-03 20:24:16]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5005;
const int M = 40005;

int ec = 1,to[M << 1],nxt[M << 1],cap[M << 1],hed[N],lev[N],cur[N];
void add_edge(int f,int t,int c){
    ++ ec; to[ec] = t; nxt[ec] = hed[f]; hed[f] = ec; cap[ec] = c;
    ++ ec; to[ec] = f; nxt[ec] = hed[t]; hed[t] = ec; cap[ec] = 0;
}

void bfs(int s,int t){
    for(int i = 1;i <= t;i ++) lev[i] = -1;
    queue <int> q;
    lev[s] = 0; q.push(s);
    while(!q.empty()){
        int u = q.front(); q.pop();
        for(int v,i = hed[u];i;i = nxt[i]){
            v = to[i];
            if(cap[i] && lev[v] == -1){
                lev[v] = lev[u] + 1;
                q.push(v);
            }
        }
    }
}

int dfs(int u,int t,int f){
    if(u == t) return f;
    for(int v,i = cur[u];i;i = nxt[i]){
        v = to[i]; cur[u] = i;
        if(lev[v] == lev[u] + 1 && cap[i]){
            int tmp = dfs(v,t,min(f,cap[i]));
            if(tmp){
                cap[i] -= tmp;
                cap[i ^ 1] += tmp;
                return tmp;
            }
        }
    }
    return 0;
}

int mxf = 0;
void dinic(int s,int t){
    while(1){
        bfs(s,t); if(lev[t] == -1) break;
        for(int i = 1;i <= t;i ++) cur[i] = hed[i];
        while(1){
            int f = dfs(s,t,0x3f3f3f3f);
            if(!f) break;
            mxf += f;
        }
    }
}

int n,m,a[55][55];
int S,T;
int dx[4] = {-1, 1, 0, 0};
int dy[4] = { 0, 0,-1, 1};

int get_id(int x,int y){
    return x * (m - 1) + y;
}

void buildedge(){
    mxf = 0;
    ec = 1;
    for(int i = 1;i <= T;i ++) hed[i] = 0;
    for(int i = 1;i <= n;i ++){
        for(int j = 1;j <= m;j ++){
            if(a[i][j]) continue;
            if((i + j) & 1){
                add_edge(S,get_id(i,j),1);
                for(int d = 0;d < 4;d ++){
                    int tx = i + dx[d];
                    int ty = j + dy[d];
                    if(tx >= 1 && tx <= n && ty >= 1 && ty <= m) add_edge(get_id(i,j),get_id(tx,ty),1);
                }
            }
            else add_edge(get_id(i,j),T,1);
        }
    }
}

void solve(){
    cin >> n >> m;
    vector <pair <int,int> > vec;
    for(int i = 1;i <= n;i ++){
        for(int j = 1;j <= m;j ++){
            char ch; cin >> ch;
            if(ch == '#') a[i][j] = 1;
            else vec.push_back({i,j});
        }
    }
    S = get_id(n,m) + 1; T = S + 1;
    buildedge();
    dinic(S,T);
    int ansmx = mxf,cnt = 0;
    for(auto [x,y] : vec){
        a[x][y] = 1;
        buildedge();
        dinic(S,T);
        if(mxf == ansmx) cnt ++;
        a[x][y] = 0;
    }
    cout << cnt << '\n';
}

int main(){
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3780kb

input:

3 3
#.#
...
#.#

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3572kb

input:

3 3
..#
...
...

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3808kb

input:

1 4
...#

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3644kb

input:

1 5
####.

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

1 6
#..###

output:

0

result:

ok 1 number(s): "0"

Test #6:

score: 0
Accepted
time: 0ms
memory: 3852kb

input:

2 5
....#
###.#

output:

3

result:

ok 1 number(s): "3"

Test #7:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

2 6
...##.
.#.###

output:

4

result:

ok 1 number(s): "4"

Test #8:

score: -100
Wrong Answer
time: 0ms
memory: 3560kb

input:

5 5
##...
##.#.
##.##
##.#.
.##..

output:

4

result:

wrong answer 1st numbers differ - expected: '7', found: '4'