publicstaticvoidsolve() { intn= io.nextInt(); char[] s = io.next().toCharArray();
longans=0L; intl= n - 1, r = n - 1; for (; l >= 0; l--) { if (s[l] == '0') { ans += r - l; r--; io.print(ans + " "); } } io.println("-1 ".repeat(r + 1)); }
classSolution { publicintminimumChanges(String s, int k) { intn= s.length();
int[][] change = newint[n][n]; for (inti=0; i < n - 1; i++) { for (intj= i + 1; j < n; j++) { change[i][j] = calc(s.substring(i, j + 1)); } }
int[][] dp = newint[n][k]; for (inti=0; i < n; i++) { Arrays.fill(dp[i], -1); } return dfs(0, s, n, k - 1, change, dp); }
privateintcalc(String s) { intn= s.length(), res = n; for (intd=1; d < n; d++) { if (n % d == 0) { intcnt=0; for (intk=0; k < d; k++) { for (inti= k, j = n - d + k; i < j; i += d, j -= d) { if (s.charAt(i) != s.charAt(j)) { cnt++; } } } res = Math.min(res, cnt); } } return res; }
privateintdfs(int i, String s, int n, int k, int[][] change, int[][] dp) { if (k == 0) { return change[i][n - 1]; }
if (dp[i][k] != -1) { return dp[i][k]; }
intres= n; for (intj= i + 1; j < n - 2 * k; j++) { res = Math.min(res, dfs(j + 1, s, n, k - 1, change, dp) + change[i][j]); } return dp[i][k] = res; } }
publicstaticvoidsolve() { inth= io.nextInt(), w = io.nextInt(); boolean[][] g = newboolean[h][w]; for (inti=0; i < h; i++) { Strings= io.next(); for (intj=0; j < w; j++) { if (s.charAt(j) == '#') { g[i][j] = true; } } } intans=0; for (inti=0; i < h; i++) { for (intj=0; j < w; j++) { if (g[i][j]) { ans++; dfs(i, j, g); } } } io.println(ans); }
privatestaticvoiddfs(int x, int y, boolean[][] g) { if (x < 0 || x >= g.length || y < 0 || y >= g[0].length || !g[x][y]) return; g[x][y] = false; for (inti= -1; i <= 1; i++) { for (intj= -1; j <= 1; j++) { dfs(x + i, y + j, g); } } }
publicstaticvoidsolve() { intn= io.nextInt(); long[][] aux = newlong[n][]; for (inti=0; i < n; i++) { longt= io.nextLong(), d = io.nextLong(); aux[i] = newlong[]{t, t + d}; } Arrays.sort(aux, (a, b) -> Long.compare(a[0], b[0]));
inti=0, ans = 0; Queue<Long> q = newPriorityQueue<>(); for (longt=0; ; t++) { if (q.isEmpty()) { if (i == n) break; t = aux[i][0]; } while (i < n && aux[i][0] == t) { q.offer(aux[i++][1]); } while (!q.isEmpty() && q.peek() < t) { q.poll(); } if (!q.isEmpty()) { ans++; q.poll(); } } io.println(ans); }