// N^3 solution to Stamp Stamp (intended) // Use the convex hull to reduce the number of candidate vectors. import java.util.*; public class StampStampN3 { public static void main(String[] args) { new StampStampN3(new Scanner(System.in)); } int W, H, oo=987654321; boolean[][] isMarked, hasInEdge, hasOutEdge; boolean isOk(int x, int y) { if (x < 0 || x >= W) return false; if (y < 0 || y >= H) return false; return true; } int score(int dx, int dy) { for (boolean[] e : hasInEdge) Arrays.fill(e, false); for (boolean[] e : hasOutEdge) Arrays.fill(e, false); for (int i=0; i= 2 && cross(H[k-2], H[k-1], pts[i]) <= 0) k--; H[k++] = pts[i]; } int half = k; for (int i=N-1; i>=0; i--) { while (k-half >= 2 && cross(H[k-2], H[k-1], pts[i]) <= 0) k--; H[k++] = pts[i]; } vec2[] res = new vec2[k]; for (int i=0; i", x, y); } } }