QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#526518#5114. Cells Coloringsilver_museWA 803ms5704kbC++201.7kb2024-08-21 17:00:122024-08-21 17:00:12

Judging History

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

  • [2024-08-21 17:00:12]
  • 评测
  • 测评结果:WA
  • 用时:803ms
  • 内存:5704kb
  • [2024-08-21 17:00:12]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define ph push_back
#define pp pop_back
using namespace std;

const int N=300,inf=1e18;
int n,m,c,d;
int row[N],col[N];
string mp[N];
set<array<int,3> >s;
bool hang[N][N],lie[N][N],vis[N][N];
vector<array<int,2> >v;
vector<int>vv;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin>>n>>m>>c>>d;
    for(int i=1;i<=n;i++) 
    {
        cin>>mp[i];
        mp[i]=" "+mp[i];
    }
    for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
        if(mp[i][j]=='.') row[i]++,col[j]++;
    for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++) 
        if(mp[i][j]=='.') s.insert({row[i]+col[j]-1,i,j});
    while(!s.empty())
    {
        auto it=s.begin();
        array<int,3>a=*it; s.erase(it);
        v.ph({a[1],a[2]}); vis[a[1]][a[2]]=1;
        for(int i=1;i<=n;i++)
            if(!vis[i][a[2]]&&mp[i][a[2]]=='.') 
            {
                s.erase({row[i]+col[a[2]]-1,i,a[2]});
                s.insert({row[i]+col[a[2]]-2,i,a[2]});
            }
        for(int j=1;j<=m;j++)
            if(!vis[a[1]][j]&&mp[a[1]][j]=='.')
            {
                s.erase({row[a[1]]+col[j]-1,a[1],j});
                s.insert({row[a[1]]+col[j]-2,a[1],j});
            }
        row[a[1]]--; col[a[2]]--;
    }
    for(auto it:v)
    {
        int k,x=it[0],y=it[1];
        for(int i=1;;i++)
            if(!hang[x][i]&&!lie[y][i]) { vv.ph(i); k=i; break; }
        hang[x][k]=1; lie[y][k]=1;
    }
    sort(vv.begin(),vv.end());
    int nv=v.size();
    int ans=d*nv;
    for(int i=0;i<nv;i++) ans=min(ans,c*vv[i]+d*(nv-i-1));
    cout<<ans<<endl;
    return 0;
}

詳細信息

Test #1:

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

input:

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

output:

4

result:

ok 1 number(s): "4"

Test #2:

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

input:

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

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: -100
Wrong Answer
time: 803ms
memory: 5704kb

input:

250 250 965680874 9042302
..**.*****..**..**.*****..***..***.**......*.***.*...***.*....*.**.*.**.*.*.****...*.******.***.************....**.*..*..***.*******.*.***.*..**..****.**.*.*..***.****..**.....***.....*.****...*...*.***..****..**.*.*******..*.*******.*.*.*.****.*.***
....**.*******.*.******...

output:

126450495376

result:

wrong answer 1st numbers differ - expected: '109972100048', found: '126450495376'