QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#613726 | #4788. Gravity | ucup-team4153# | ML | 27ms | 196240kb | C++17 | 2.7kb | 2024-10-05 14:35:23 | 2024-10-05 14:35:23 |
Judging History
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;
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 t[N*N];
bool vis[N*N];
vector<int>E[N][N];
int id(int x,int y){
return find(x*m+y);
}
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);
}
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(grid[i][j]=='.')continue;
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: 27ms
memory: 196240kb
input:
10 10 .......... ..######.. ..#....#.. ..#.#..#.. ..#..#.#.. ..#....#.. ..######.. .......... ..#....#.. .......#..
output:
.......... .......... ..######.. ..#....#.. ..#....#.. ..#....#.. ..#.##.#.. ..######.. .......#.. ..#....#..
result:
ok 10 lines
Test #2:
score: -100
Memory Limit Exceeded
input:
1583 1799 #..###..##..#.####.##.##.###..#.....##..#.#.#.#......#.....##..#.##...#.#....#..##.###...#...##.###.#.....#.##.###...#..##.#...###..#.###.#...###..#.......#...#....#.#..#...##........#.#..#..##.....###...#..#.####..####...#..##......#........#..#.##.##..#..#....##.##.##..#..##.....###....#...
output:
...............................................................................................................................................................................................................................................................................................................