List<String> cp = newArrayList<>(Collections.nCopies(n + 1, "")); for (inti=1; i <= n; i++) { cp.set(i, sc.next()); }
varis=newint[h + 1]; Map<Integer, Integer> res = newHashMap<>();
for (inti=0; i < h; i++) { intmaxp=0, P = -1; for (intk=1; k <= n; k++) { if (ck(cp.get(k), s, i, is) && maxp < cp.get(k).length()) { maxp = cp.get(k).length(); P = k; } } if (P != -1) { res.put(i, P); work(cp.get(P), is, i); } }
for (inti=0; i < h; i++) { if (is[i] == 0) { System.out.println(-1); return; } }
List<Move> ans = newArrayList<>(); for (var entry : res.entrySet()) { intx= entry.getKey(), y = entry.getValue(); inttp=0; for (inti=0; i < cp.get(y).length(); i++) { if (is[x + i] >= 2) { tp++; } } if (tp == cp.get(y).length()) { for (inti=0; i < cp.get(y).length(); i++) { is[x + i]--; } } else { ans.add(newMove(y, x)); } }