fork download
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4.  
  5. using namespace __gnu_pbds;
  6. using namespace std;
  7.  
  8. #define PG_Mazen ios_base::sync_with_stdio( 0 ), cin.tie( 0 ), cout.tie( 0 );
  9. #define el '\n'
  10. #define sp ' '
  11. #define all(v) v.begin(), v.end()
  12. #define r_all(v) (v).rbegin(), (v).rend()
  13. #define SZ(v) (v).size()
  14. #define pb(n) push_back(n)
  15. #define eb(n, m) emplace_back(n, m)
  16. #define YES cout << "YES\n"
  17. #define NO cout << "NO\n"
  18. #define ll long long
  19. #define ld long double
  20. #define pii pair<int, int>
  21. #define pll pair<ll,ll>
  22. #define F first
  23. #define S second
  24. #define loop int t; cin >> t; for(int i=1;i<=t;++i)
  25. #define f0(i, st, n) for(int i=st;i<n;++i)
  26. #define f1(i, st, n) for(int i=st;i<=n;++i)
  27. #define fe(it, n) for(auto &it : n)
  28. #define mms(arr, val) memset(arr, val, sizeof arr)
  29. #define mmv(vec, val) memset(vec[0], val, sizeof(vec) * SZ(vec))
  30. #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
  31.  
  32. const int N = 2e5 + 5, MOD = 998244353, oo = 0x3f3f3f3f;
  33. const ll ooo = 0x3f3f3f3f3f3f3f3f;
  34.  
  35. void testCase() {
  36. int n;
  37. string s;
  38. cin >> n >> s;
  39. reverse(s.begin(), s.end());
  40. vector<int> ans;
  41. ans.push_back(0);
  42. queue<int> q;
  43. for(int i = 0; i < n; ++i) {
  44. if (s[i] == '0')
  45. q.push(i);
  46. }
  47. for (int i = 0; i < n; ++i) {
  48. if (q.empty()) {
  49. ans.push_back(-1);
  50. continue;
  51. }
  52. int head = q.front(), lst = ans.back();
  53. ans.push_back(head - i + lst);
  54. q.pop();
  55. }
  56. for (int i = 1; i < ans.size(); ++i)
  57. cout << ans[i] << ' ';
  58. cout << '\n';
  59. }
  60.  
  61. int main() {
  62. PG_Mazen
  63. //freopen("input.txt", "r", stdin);
  64. //freopen("output.txt", "w", stdout);
  65. loop testCase();
  66. }
Runtime error #stdin #stdout 0.01s 5424KB
stdin
Standard input is empty
stdout
Standard output is empty