QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#613659#4788. Gravityucup-team4153#ML 6ms13904kbC++202.7kb2024-10-05 14:26:262024-10-05 14:26:29

Judging History

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

  • [2024-10-05 14:26:29]
  • 评测
  • 测评结果:ML
  • 用时:6ms
  • 内存:13904kb
  • [2024-10-05 14:26:26]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=2e3+5;
const int INF=0x3f3f3f3f;
int n,m;
char grid[N][N];
bool ot[N][N];
struct node{
    int id,t;
    bool operator < (const node &oth) const {
        return t>oth.t;
    }
};
priority_queue<node>que;
set<int>pos[N];
int fa[N*N];
int find(int x){
    return fa[x]==x?x:fa[x]=find(fa[x]);
}
void uni(int x,int y){
    int fx=find(x),fy=find(y);
    if(fx==fy)return;
    fa[fx]=fy;
}
int dir[4][2]={0,1,0,-1,1,0,-1,0};
vector<array<int,2>>vec[N*N];
int id[N][N];
int t[N*N];
bool vis[N*N];
vector<int>E[N][N];
int du[N*N];
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for(int i=n-1;i>=0;i--){
        for(int j=0;j<m;j++){
            cin>>grid[i][j];
        }
    }
    for(int i=0;i<n*m;i++)fa[i]=i,t[i]=INF;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(grid[i][j]=='.')continue;
            for(int op=0;op<4;op++){
                int x=i+dir[op][0],y=j+dir[op][1];
                if(x<0 || x>=n || y<0 || y>=m || grid[x][y]=='.')continue;
                uni(i*m+j,x*m+y);
            }
            pos[j].insert(i);
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(grid[i][j]=='.')continue;
            id[i][j]=find(i*m+j);
            vec[id[i][j]].push_back({i,j});
            t[id[i][j]]=min(t[id[i][j]],i);
        }
    }
    for(int j=0;j<m;j++){
        int pre=-1;
        for(int i=n-1;i>=0;i--){
            if(grid[i][j]=='.')continue;
            if(pre!=-1 && id[i][j]!=id[pre][j]) {
                E[i][j].push_back(pre);
//                du[id[pre][j]]++;
//                cout<<i<<' '<<j<<' '<<pre<<' '<<j<<'\n';
            }
            pre=i;
        }
    }
    for(int i=0;i<n*m;i++){
        if(fa[i]==i && grid[i/m][i%m]=='#'){// && du[i]==0
            que.push({i,t[i]});
//            cout<<i/m<<' '<<i%m<<'\n';
        }
    }
    while(!que.empty()){
        auto now=que.top();que.pop();
        if(vis[now.id])continue;
        vis[now.id]=true;
        for(auto u:vec[now.id]){
            auto [x,y]=u;
            ot[x-now.t][y]=true;
            for(auto v:E[x][y]){
                if(v-(x-now.t)-1<t[id[v][y]]){
                    t[id[v][y]]=v-(x-now.t)-1;
                    que.push({id[v][y],t[id[v][y]]});
                }
//                du[id[v][y]]--;
//                if(du[id[v][y]]==0)que.push({id[v][y],t[id[v][y]]});
            }
        }
    }
    for(int i=n-1;i>=0;i--){
        for(int j=0;j<m;j++){
//            cout<<grid[i][j];
            if(ot[i][j])cout<<'#';
            else cout<<'.';
        }cout<<'\n';
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 6ms
memory: 13904kb

input:

10 10
..........
..######..
..#....#..
..#.#..#..
..#..#.#..
..#....#..
..######..
..........
..#....#..
.......#..


output:

..........
..........
..######..
..#....#..
..#....#..
..#....#..
..#.##.#..
..######..
.......#..
..#....#..

result:

ok 10 lines

Test #2:

score: -100
Memory Limit Exceeded

input:

1583 1799
#..###..##..#.####.##.##.###..#.....##..#.#.#.#......#.....##..#.##...#.#....#..##.###...#...##.###.#.....#.##.###...#..##.#...###..#.###.#...###..#.......#...#....#.#..#...##........#.#..#..##.....###...#..#.####..####...#..##......#........#..#.##.##..#..#....##.##.##..#..##.....###....#...

output:

...............................................................................................................................................................................................................................................................................................................

result: