QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#446595 | #4788. Gravity | do_while_true | RE | 7ms | 71200kb | C++20 | 3.4kb | 2024-06-17 13:46:55 | 2024-06-17 13:46:56 |
Judging History
answer
#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<random>
#include<array>
#include<assert.h>
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define dbg(x) cerr<<"In Line "<< __LINE__<<" the "<<#x<<" = "<<x<<'\n'
#define dpi(x,y) cerr<<"In Line "<<__LINE__<<" the "<<#x<<" = "<<x<<" ; "<<"the "<<#y<<" = "<<y<<'\n'
#define DE(fmt,...) fprintf(stderr, "Line %d : " fmt "\n",__LINE__,##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef pair<ll,int>pli;
typedef pair<ll,ll>pll;
typedef pair<int,ll>pil;
typedef vector<int>vi;
typedef vector<ll>vll;
typedef vector<pii>vpii;
typedef vector<pll>vpll;
template<typename T>T cmax(T &x, T y){return x=x>y?x:y;}
template<typename T>T cmin(T &x, T y){return x=x<y?x:y;}
template<typename T>
T &read(T &r){
r=0;bool w=0;char ch=getchar();
while(ch<'0'||ch>'9')w=ch=='-'?1:0,ch=getchar();
while(ch>='0'&&ch<='9')r=r*10+(ch^48),ch=getchar();
return r=w?-r:r;
}
template<typename T1,typename... T2>
void read(T1 &x,T2& ...y){read(x);read(y...);}
const int mod=998244353;
inline void cadd(int &x,int y){x=(x+y>=mod)?(x+y-mod):(x+y);}
inline void cdel(int &x,int y){x=(x-y<0)?(x-y+mod):(x-y);}
inline int add(int x,int y){return (x+y>=mod)?(x+y-mod):(x+y);}
inline int del(int x,int y){return (x-y<0)?(x-y+mod):(x-y);}
int qpow(int x,int y){
int s=1;
while(y){
if(y&1)s=1ll*s*x%mod;
x=1ll*x*x%mod;
y>>=1;
}
return s;
}
const int N=1000010;
int n,m,tot;
int bl[N],et;
string a[N],b[N];
char str[N];
int id(int x,int y){return (x-1)*m+y;}
int X(int o){return (o-1)/m+1;}
int Y(int o){return o%m==0?m:o%m;}
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
void dfs(int x,int y,int o){
bl[id(x,y)]=o;
for(int i=0;i<4;i++){
int u=x+dx[i],v=y+dy[i];
if(u>=1&&u<=n&&v>=1&&v<=m&&!bl[id(u,v)]&&a[u][v]=='#')
dfs(u,v,o);
}
}
int dis[N],vis[N];
vpii eg[N];
signed main(){
#ifdef do_while_true
// assert(freopen("data.in","r",stdin));
// assert(freopen("data.out","w",stdout));
#endif
read(n,m);tot=n*m;
for(int i=1;i<=n;i++){
scanf("%s",str+1);
a[i].resize(m+1);b[i].resize(m+1);
for(int j=1;j<=m;j++)a[i][j]=str[j];
}
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)if(a[i][j]=='#'&&!bl[id(i,j)]){
++et;
dfs(i,j,et);
}
for(int i=1;i<=et;i++)dis[i]=n+1;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)if(a[i][j]=='#'){
cmin(dis[bl[id(i,j)]],n-i);
int p=0;
for(int k=i-1;k>=1;k--)if(a[k][j]=='#'){
p=k;break;
}
if(!p)continue;
if(bl[id(i,j)]!=bl[id(p,j)]){
eg[bl[id(i,j)]].pb(bl[id(p,j)],i-p-1);
}
}
priority_queue<pii,vpii,greater<pii>>q;
for(int i=1;i<=et;i++)q.push(mp(dis[i],i));
while(!q.empty()){
int x=q.top().se;q.pop();
if(vis[x])continue;
vis[x]=1;
for(auto [v,w]:eg[x]){
if(dis[v]>dis[x]+w){
dis[v]=dis[x]+w;
q.push(mp(dis[v],v));
}
}
}
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
b[i][j]='.';
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)if(a[i][j]=='#'){
b[i+dis[bl[id(i,j)]]][j]='#';
}
cerr<<'\n';
for(int i=1;i<=n;i++,puts(""))
for(int j=1;j<=m;j++)
putchar(b[i][j]);
#ifdef do_while_true
// cerr<<'\n'<<"Time:"<<1.0*clock()/CLOCKS_PER_SEC*1000<<" ms"<<'\n';
#endif
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 7ms
memory: 71200kb
input:
10 10 .......... ..######.. ..#....#.. ..#.#..#.. ..#..#.#.. ..#....#.. ..######.. .......... ..#....#.. .......#..
output:
.......... .......... ..######.. ..#....#.. ..#....#.. ..#....#.. ..#.##.#.. ..######.. .......#.. ..#....#..
result:
ok 10 lines
Test #2:
score: -100
Runtime Error
input:
1583 1799 #..###..##..#.####.##.##.###..#.....##..#.#.#.#......#.....##..#.##...#.#....#..##.###...#...##.###.#.....#.##.###...#..##.#...###..#.###.#...###..#.......#...#....#.#..#...##........#.#..#..##.....###...#..#.####..####...#..##......#........#..#.##.##..#..#....##.##.##..#..##.....###....#...