Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long LL;
- const int maxn = 5000 + 100;
- int n, last;
- char str[maxn];
- int l[maxn], r[maxn];
- int main() {
- #ifdef ExRoc
- freopen("test.txt", "r", stdin);
- #endif
- ios::sync_with_stdio(false);
- scanf("%d%s", &n, str + 1);
- last = -1e7;
- for (int i = 1; i <= n; ++i) {
- if (str[i] == '1') {
- last = i;
- }
- l[i] = last;
- }
- last = 1e7;
- for (int i = n; i >= 1; --i) {
- if (str[i] == '1') {
- last = i;
- }
- r[i] = last;
- }
- for (int i = 1; i <= n; ++i) {
- if (str[i] == '1') {
- continue;
- }
- int ans = min(i - l[i], r[i] - i);
- if (ans >= n) {
- cout << -1 << " ";
- } else {
- cout << ans << " ";
- }
- }
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement