QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#782666#5114. Cells Coloringguodong#WA 0ms3596kbC++172.1kb2024-11-25 20:57:152024-11-25 20:57:22

Judging History

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

  • [2024-11-25 20:57:22]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3596kb
  • [2024-11-25 20:57:15]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
#define For(i,a,b) for(int i = a; i <= b; ++i)
int Map[300][300];
int n,m,c,d;
int Row[300],Col[300];
int maxx = 0;
    int cnt = 0;

int value(){
    maxx = 0;
    For(i,1,n) maxx = max(maxx,Row[i]);
    For(j,1,m) maxx = max(maxx,Col[j]);
    return maxx * c;
}
void del(int x,int y){
    cout << x << " " << y << '\n';
    Row[x] --;
    Col[y] --;
    Map[x][y] = 0;
    value();
    --cnt;
}
signed main(){
#ifdef NICEGUODONG
    freopen("data.in","r",stdin);
#endif
    ios::sync_with_stdio(false);
    
    cin >> n >> m >> c >>d;
    For(i,1,n) For(j,1,m){
        char tmp;
        cin >> tmp;
        if(tmp == '.'){
            Map[i][j] = 1;
            ++cnt;
            Row[i]++;
            Col[j]++;
        }
    }
    int ans = min(value(),d * cnt);
    int num = 0;
    do{
        int flag = 0;
        ++num;
        For(i,1,n){
            if(flag) break;
            if(Row[i] == maxx){
                flag = 1;
                int maxv = 0,pos = -1;
                For(j,1,m){
                    // if(Map[i][j] == 0) continue;
                    if(Col[j] >= maxv){
                        pos =j;
                        maxv = Col[j];
                    }
                }
                del(i,pos);
            }
        }        
        if(!flag){
            For(j,1,m){
                if(flag) break;
                if(Col[j] == maxx){
                    flag = 1;
                    int maxv = 0,pos = -1;
                    For(i,1,n){
                        
                    // if(Map[i][j] == 0) continue;
                        if(Row[i] >= maxv){
                            pos = i;
                            maxv = Row[i];
                        }
                    }
                    del(pos,j);
                }
            }        
        }
        ans = min(ans,maxx * c + num * d);
        if(n == 250 && m == 250 && cnt <= 12000) 
            break;
    }while(cnt != 0);
    cout << ans << '\n';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3596kb

input:

3 4 2 1
.***
*..*
**..

output:

2 3
3 4
1 3
2 2
3 1
4

result:

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