QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#308370 | #4788. Gravity | KLPP# | WA | 3ms | 10192kb | C++20 | 2.2kb | 2024-01-20 00:41:28 | 2024-01-20 00:41:29 |
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];
pair<int,int> nxt[3000][3000];
int col[3000][3000];
int cnt;
int n,m;
vector<pair<int,int> > nei[1000000];
bool in(int a, int b){
if(a>=0 && a<n && b>=0 && b<m && table[a][b]=='#')return true;
return false;
}
void DFS(int a, int b){
col[a][b]=cnt;
rep(dx,-1,2){
rep(dy,-1,2){
if(abs(dx)+abs(dy)==1 && in(a+dx,b+dy) && col[a+dx][b+dy]==-1){
DFS(a+dx,b+dy);
}
}
}
}
lld dist[1000000];
string ans[3000];
void solve(){
cin>>n>>m;
rep(i,0,n)cin>>table[i];
rep(j,0,m){
pair<int,int> p={-1,-1};
rep(i,0,n){
if(table[i][j]=='#'){
nxt[i][j]=p;
p={i,j};
}
}
nxt[n][j]=p;
}
cnt=1;
rep(i,0,n){
rep(j,0,m){
col[i][j]=-1;
}
}
rep(i,0,n){
rep(j,0,m){
if(col[i][j]==-1 && in(i,j))DFS(i,j),cnt++;
}
}
rep(j,0,m)col[n][j]=0;
rep(i,0,n+1){
rep(j,0,m){
if((i==n || table[i][j]=='#') && nxt[i][j].first!=-1){
//cout<<col[i][j]<<" "<<col[nxt[i][j].first][nxt[i][j].second]<<" "<<i-nxt[i][j].first<<endl;
nei[col[i][j]].push_back({col[nxt[i][j].first][nxt[i][j].second],i-nxt[i][j].first-1});
}
}
}
priority_queue<pair<lld,int> >pq;
rep(i,0,cnt)dist[i]=1e18;
pq.push({0,0});
dist[0]=0;
while(!pq.empty()){
lld d=-pq.top().first;
int v=pq.top().second;
pq.pop();
if(d>dist[v])continue;
trav(a,nei[v]){
if(dist[a.first]>dist[v]+a.second){
dist[a.first]=dist[v]+a.second;
pq.push({-dist[a.first],a.first});
}
}
}
rep(i,0,cnt)cout<<dist[i]<<" ";
cout<<"\n";
rep(i,0,n){
rep(j,0,m)ans[i]+=".";
}
rep(i,0,n){
rep(j,0,m){
if(table[i][j]=='#'){
ans[i+dist[col[i][j]]][j]='#';
}
}
}
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: 0
Wrong Answer
time: 3ms
memory: 10192kb
input:
10 10 .......... ..######.. ..#....#.. ..#.#..#.. ..#..#.#.. ..#....#.. ..######.. .......... ..#....#.. .......#..
output:
0 1 3 2 1 0 .......... .......... ..######.. ..#....#.. ..#....#.. ..#....#.. ..#.##.#.. ..######.. .......#.. ..#....#..
result:
wrong answer 1st lines differ - expected: '..........', found: '0 1 3 2 1 0 '