Ac日记——Distances to Zero codeforces 803b
思路:
水题;
代码:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define maxn 200005 int ai[maxn],bi[maxn],ci[maxn],n; inline void in(int &now) { char Cget=getchar();now=0; while(Cget>'9'||Cget<'0') Cget=getchar(); while(Cget>='0'&&Cget<='9') { now=now*10+Cget-'0'; Cget=getchar(); } } int main() { in(n);int cnt=maxn+1,pos=maxn+1; for(int i=1;i<=n;i++) in(ai[i]); for(int i=1;i<=n;i++) bi[i]=ai[i]?++cnt:cnt=0; for(int i=n;i>=1;i--) ci[i]=ai[i]?++pos:pos=0; for(int i=1;i<=n;i++) printf("%d ",min(bi[i],ci[i])); return 0; }