QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#308376 | #4788. Gravity | KLPP# | WA | 116ms | 20316kb | C++20 | 1.7kb | 2024-01-20 00:56:56 | 2024-01-20 00:56:57 |
Judging History
answer
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int lld;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define trav(a,v) for(auto a:v)
string table[3000];
int n,m;
bool in(int a, int b){
if(a>=0 && a<=n && b>=0 && b<m)return true;
return false;
}
short dist[3000][3000];
deque<pair<pair<int,int>,int> >d;
string ans[3000];
void solve(){
cin>>n>>m;
rep(i,0,n)cin>>table[i];
table[n]="";
rep(i,0,m)table[n]+=".";
rep(i,0,n){
rep(j,0,m){
dist[i][j]=30000;
}
}
rep(j,0,m){
dist[n][j]=0;
d.push_front({{n,j},0});
}
while(!d.empty()){
int x=d.front().first.first;
int y=d.front().first.second;
int D=d.front().second;
d.pop_front();
if(D>dist[x][y])continue;
rep(dx,-1,2){
rep(dy,-1,2){
if(abs(dx)+abs(dy)==1 && in(x+dx,y+dy) && dist[x+dx][y+dy]>dist[x][y]+(table[x+dx][y+dy]=='.')){
if(table[x+dx][y+dy]=='.' && dx!=-1)continue;
dist[x+dx][y+dy]=dist[x][y]+(table[x+dx][y+dy]=='.');
if(table[x+dx][y+dy]=='.'){
d.push_back({{x+dx,y+dy},dist[x][y]+1});
}else d.push_front({{x+dx,y+dy},dist[x][y]});
}
}
}
}
rep(i,0,n){
ans[i]="";
rep(j,0,m)ans[i]+=".";
}
rep(i,0,n){
rep(j,0,m){
//cout<<dist[i][j]<<" ";
if(table[i][j]=='#'){
ans[i+dist[i][j]][j]='#';
}
}//cout<<endl;
}
rep(i,0,n)cout<<ans[i]<<"\n";
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int tt=1;
//cin>>tt;
while(tt--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4056kb
input:
10 10 .......... ..######.. ..#....#.. ..#.#..#.. ..#..#.#.. ..#....#.. ..######.. .......... ..#....#.. .......#..
output:
.......... .......... ..######.. ..#....#.. ..#....#.. ..#....#.. ..#.##.#.. ..######.. .......#.. ..#....#..
result:
ok 10 lines
Test #2:
score: -100
Wrong Answer
time: 116ms
memory: 20316kb
input:
1583 1799 #..###..##..#.####.##.##.###..#.....##..#.#.#.#......#.....##..#.##...#.#....#..##.###...#...##.###.#.....#.##.###...#..##.#...###..#.###.#...###..#.......#...#....#.#..#...##........#.#..#..##.....###...#..#.####..####...#..##......#........#..#.##.##..#..#....##.##.##..#..##.....###....#...
output:
...............................................................................................................................................................................................................................................................................................................
result:
wrong answer 253rd lines differ - expected: '................................................................', found: '................................................................'