#include #include #include #include #include #include #include #define pt cout << #define nl '\n' #define in cin >> using namespace std; // -------- START RAII HELPERS-------- unsigned long allocated_mem = 0; void *alloc(size_t size) { void *ptr = malloc(size); if (ptr == nullptr) { cerr << "Memory allocation failed" << endl; return nullptr; } allocated_mem += 1; return ptr; } void dealloc(void *ptr) { if (ptr) free(ptr); allocated_mem -= 1; } bool assert_alloc() { return !allocated_mem; } // -------- END RAII HELPERS-------- struct Move { char player; int moveX; int moveY; }; struct Moves { int x; int y; vector moves; }; Moves serialize(const string &s) { Moves result; istringstream iss(s); iss >> result.x >> result.y; result.x <<= 1; result.y <<= 1; string player; int x, y; while (iss >> player >> x >> y) { if (player == "END") break; result.moves.push_back({player[0], x, y}); } return result; } void initBoard(char **board, int x, int y) { for (int i = 0; i < x; ++i) { for (int j = 0; j < y; j++) { board[i][j] = (j&1 || i&1) ? ' ': '.'; } } } char **allocAndInitBoard(int x, int y) { char **board = static_cast(alloc(sizeof(char *) * x)); for (int i = 0; i < x; ++i) { board[i] = static_cast(alloc(sizeof(char) * y)); } initBoard(board, x, y); return board; } void deallocBoard(char **board, int x) { for (int i = 0; i < x; ++i) { dealloc(board[i]); } dealloc(board); } void printBoard(char **board, int x, int y) { for (int i = 0; i < x; ++i) { for (int j = 0; j < y; ++j) { pt board[i][j]; } pt nl; } } void solve(Moves moves, char **board) { } int init(char *fileName) { // --- IO START --- FILE *inp = fopen(fileName, "r"); if (inp == nullptr) { cerr << "File not found" << endl; return 1; } fseek(inp, 0L, SEEK_END); const long sz = ftell(inp); fseek(inp, 0L, SEEK_SET); char *fileInpPtr = static_cast(alloc(sz + 1 * sizeof(char))); fileInpPtr[sz] = '\0'; for (int i = 0; i < sz; ++i) { fscanf(inp, "%c", &fileInpPtr[i]); } // --- IO END --- // --- ALGORITHM START --- Moves moves = serialize(fileInpPtr); char **board = allocAndInitBoard(moves.x, moves.y); solve(moves, board); // --- ALGORITHM END --- // --- CLEANUP START --- dealloc(fileInpPtr); deallocBoard(board, moves.x); fclose(inp); if (!assert_alloc()) { cerr << "Memory leak detected" << endl; return 1; } // --- CLEANUP END --- return 0; } int main(int argc, char **argv) { if (argc < 2) { cerr << "No input file provided" << endl; return 1; } return init(argv[1]); }