import java.util.*; public class zamboni_font { public static void main(String[] args) { new zamboni_font(new Scanner(System.in)); } // For a given step size and modulus, find all the positions in order for // each of the types of modulus. Runs in O(modulus). ArrayList findCycles(int startStep, int modulus) { ArrayList res = new ArrayList(); boolean[] seen = new boolean[modulus]; int pos = startStep; while (!seen[pos]) { seen[pos] = true; res.add(pos); pos = (pos+4)%modulus; } return res; } char getColor(int ord) { return (char)('A'+ord); } public zamboni_font(Scanner in) { int R = in.nextInt(); int C = in.nextInt(); int startRow = R-in.nextInt(); int startCol = in.nextInt()-1; long numSteps = in.nextLong(); char[][] grid = new char[R][C]; for (int r=0; r timeColColored[c]) grid[r][c] = rowColor[r]; else if (timeRowColored[r] < timeColColored[c]) grid[r][c] = colColor[c]; } } // *** END PAINT STRIPES *** // Place the Zamboni at the ending location. grid[vertical.finalRow][horizontal.finalRow] = '@'; // Print the answer for (int r=R-1; r>=0; r--) System.out.println(new String(grid[r])); } // Class to solve the 1D version of this problem. // This class cuts the work in half. You solve vertical and horizontal both // by using this class and changing the parameters. The class is coded // from the perspective of being vertical. class Solver1D { int N, finalRow; long numUp, numDown; long[] upCounter, downCounter; ArrayList upEvents, downEvents; public Solver1D(int NN, int startLoc, int startLen, long numSteps) { N = NN; numUp = (numSteps+1)/2; // Gives the number of up events. numDown = numSteps-numUp; // Gives the number of down events. upEvents = findCycles(startLen%N, N); downEvents = findCycles((startLen+2)%N, N); upCounter = determineCounts(upEvents, numUp); downCounter = determineCounts(downEvents, numDown); finalRow = startLoc; for (int s=0; s events, long numSteps) { long[] res = new long[N]; if (events.size() == 0) return res; long numFull = numSteps / events.size(); for (int v : events) res[v] += numFull; int steps = (int)(numSteps % events.size()); for (int i=0; i