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); }
int[] prefix = newint[n]; int[] suffix = newint[n]; for (intk=0; k < n; k++) { Strings= io.next();
for (inti=0; i < s.length() && prefix[k] < t.length(); i++) { if (s.charAt(i) == t.charAt(prefix[k])) { prefix[k]++; } }
for (inti=0; i < s.length() && suffix[k] < t.length(); i++) { if (s.charAt(s.length() - 1 - i) == t.charAt(t.length() - 1 - suffix[k])) { suffix[k]++; } } }
Arrays.sort(suffix);
longans=0L; for (inti=0; i < n; i++) { intlo=0, hi = n - 1; while (lo <= hi) { intmid= lo + (hi - lo) / 2; if (prefix[i] + suffix[mid] >= t.length()) hi = mid - 1; else lo = mid + 1; } ans += n - lo; } io.println(ans); }
publicstaticvoidsolve() { intn= io.nextInt(), m = io.nextInt();
int[] in = newint[n]; List<int[]>[] g = newList[n]; Arrays.setAll(g, k -> newArrayList<>()); for (inti=0; i < m; i++) { intu= io.nextInt() - 1, v = io.nextInt() - 1, b = io.nextInt(), c = io.nextInt(); g[u].add(newint[]{v, b, c}); in[v]++; }
doublelo=0, hi = 1e4; while (hi - lo >= 1e-10) { doublemid= lo + (hi - lo) / 2; if (check(g, in.clone(), mid)) lo = mid; else hi = mid; } io.println(lo); }
dist[0] = 0; for (intu=0; u < n; u++) { for (int[] t : g[u]) { intv= t[0], b = t[1], c = t[2]; if (dist[v] < dist[u] + b - c * x) { dist[v] = dist[u] + b - c * x; } } }