Skip to content

Instantly share code, notes, and snippets.

@gbrls
Created May 29, 2020 01:00
Show Gist options
  • Select an option

  • Save gbrls/e37b619ad35d53738f84ca6fba5b4eb3 to your computer and use it in GitHub Desktop.

Select an option

Save gbrls/e37b619ad35d53738f84ca6fba5b4eb3 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
#define ii pair<int,int>
using namespace std;
const int M = 501;
int n,m;
char mat[M][M]={0};
void fall(int i, int j) {
while(i<n && mat[i][j]!='#') {
mat[i][j]='o';
i++;
}
if(mat[i][j]=='#') {
int k;
int l;
for(k=0;(j+k)<m;k++) {
if(mat[i][j+k]=='#') {
if(i>0) mat[i-1][j+k]='o';
} else {
if(i>0 && mat[i][j+k]!='o') fall(i-1,j+k);
break;
}
}
for(l=0;(j+l)>=0;l--) {
if(mat[i][j+l]=='#') {
if(i>0) mat[i-1][j+l]='o';
} else {
if(i>0 && mat[i-1][j+l]!='o') fall(i-1,j+l);
break;
}
}
}
}
int main() {
scanf("%d%d",&n,&m); getchar();
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
mat[i][j]=getchar();
}
getchar();
}
for(int i=0;i<m;i++) {
if(mat[0][i]=='o') fall(0,i);
}
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
cout<<mat[i][j];
}
cout<<'\n';
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment