#include #include #include #include #include using namespace std; typedef vector> Board; unordered_map>>> figures_and_rotations{ {0, { { {0,0}, {-1,0}, {-1,-1}, {0,-1} }, { {0,0}, {0,1}, {-1,0}, {-1,1} }, { {0,0}, {0,1}, {1,1}, {1,0} }, { {0,0}, {1,0}, {1,-1}, {0,-1} } }}, {1, { { {0,0}, {0,-1}, {-1,0} }, { {0,0}, {-1,0}, {0,1} }, { {0,0}, {0,1}, {1,0} }, { {0,0}, {0,-1}, {1,0} } }}, {2, { { {0,0}, {0,-1}, {0,-2}, {-1,0} }, { {0,0}, {-1,0}, {-2,0}, {0,1} }, { {0,0}, {0,1}, {0,2}, {1,0} }, { {0,0}, {0,-1}, {1,0}, {2,0} } }}, {3, { { {0,0}, {0,-1}, {0,-2}, {0,-3} }, { {0,0}, {-1,0}, {-2,0}, {-3,0} }, { {0,0}, {0,1}, {0,2}, {0,3} }, { {0,0}, {1,0}, {2,0}, {3,0} } }}, {4, { { {0,0}, {-1,0}, {-2,0}, {-1,-1} }, { {0,0}, {0,1}, {0,2}, {-1,1} }, { {0,0}, {1,0}, {2,0}, {1,1} }, { {0,0}, {0,-1}, {0,-2}, {1,-1} } }} }; bool canPlace(const Board& board, int r, int c, const vector>& shape) { int N = board.size(); for (auto& p : shape) { int nr = r + p.first; int nc = c + p.second; if (nr < 0 || nr >= N || nc < 0 || nc >= N) return false; if (board[nr][nc]) return false; } return true; } void placeBlock(Board& board, int r, int c, const vector>& shape) { for (auto& p : shape) { board[r + p.first][c + p.second] = true; } } void clearBoard(Board& board) { int N = board.size(); vector fullRow(N, true), fullCol(N, true); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (!board[i][j]) { fullRow[i] = false; break; } } } for (int j = 0; j < N; j++) { for (int i = 0; i < N; i++) { if (!board[i][j]) { fullCol[j] = false; break; } } } for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (fullRow[i] || fullCol[j]) board[i][j] = false; } } } vector> getTargetCells(const Board& board) { vector> targets; int N = board.size(); int dx[4] = { 1, -1, 0, 0 }; int dy[4] = { 0, 0, 1, -1 }; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (!board[i][j]) { bool adjacent = false; for (int k = 0; k < 4; k++) { int ni = i + dx[k], nj = j + dy[k]; if (ni >= 0 && ni < N && nj >= 0 && nj < N && board[ni][nj]) { adjacent = true; break; } } if (adjacent) { targets.push_back({ i, j }); } } } } return targets; } bool findPlacement(Board& board, const vector>& shape, int& place_r, int& place_c) { vector> targets = getTargetCells(board); for (auto cell : targets) { int r = cell.first, c = cell.second; if (canPlace(board, r, c, shape)) { place_r = r; place_c = c; return true; } } int N = board.size(); for (int i = N - 1; i >= 0; i--) { for (int j = 0; j < N; j++) { if (!board[i][j] && canPlace(board, i, j, shape)) { place_r = i; place_c = j; return true; } } } return false; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ifstream inp("block.in"); int N; long long a, b, c, d, e, f; inp >> N >> a >> b >> c >> d >> e >> f; inp.close(); Board board(N, vector(N, false)); vector> moves; const int MAX_MOVES = 100000; for (int move = 0; move < MAX_MOVES; move++) { c = (c ^ a) + b; f = (f ^ d) + e; int fig = c % 5; int rot = f % 4; const vector>& shape = figures_and_rotations[fig][rot]; int place_r = -1, place_c = -1; if (!findPlacement(board, shape, place_r, place_c)) break; moves.push_back({ place_r + 1, place_c + 1 }); placeBlock(board, place_r, place_c, shape); clearBoard(board); } ofstream out("block.out"); out << moves.size() << "\n"; for (auto& p : moves) out << p.first << " " << p.second << "\n"; return 0; }