/* #include "testlib.h" int main(int argc, char* argv[]){ registerValidation(argc, argv); int H = inf.readInt(1,1'000'000); inf.readSpace(); int W = inf.readInt(1, 4'000'000); ensuref((long long)H * (long long)W <= 4'000'000, "HxW violation"); inf.readEoln(); for(int i = 0; i < H; i++){ for(int j = 0; j < W; j++){ if(j > 0){ inf.readSpace(); } int A = inf.readInt(0, 1'000'000'000); } inf.readEoln(); } inf.readEof(); } */ #include #include using namespace std; namespace Validator { constexpr size_t MAX_INPUT_SIZE = 64ULL << 20; // 64 MiB static char buf[MAX_INPUT_SIZE + 1]; static char* p; static char* ed; [[noreturn]] inline void fail(const char* msg) { fprintf(stderr, "validation failed: %s\n", msg); _exit(1); } inline void init() { size_t n = 0; while (n <= MAX_INPUT_SIZE) { ssize_t r = read( STDIN_FILENO, buf + n, MAX_INPUT_SIZE + 1 - n ); if (r < 0) fail("read error"); if (r == 0) break; n += (size_t)r; if (n > MAX_INPUT_SIZE) { fail("input too large"); } } p = buf; ed = buf + n; } inline int readInt(int lo, int hi) { if (p == ed || *p < '0' || *p > '9') { fail("integer expected"); } unsigned int x = 0; do { x = x * 10 + (*p - '0'); ++p; if (x > (unsigned int)hi) { fail("integer out of range"); } } while (p != ed && '0' <= *p && *p <= '9'); if (x < (unsigned int)lo) { fail("integer out of range"); } return (int)x; } inline void readSpace() { if (p == ed || *p != ' ') { fail("space expected"); } ++p; } inline void readEoln() { if (p == ed) { fail("end of line expected"); } if (*p == '\n') { ++p; return; } if (*p == '\r') { ++p; if (p == ed || *p != '\n') { fail("end of line expected"); } ++p; return; } fail("end of line expected"); } inline void readEof() { if (p != ed) { fail("EOF expected"); } } } // namespace Validator int main() { using namespace Validator; init(); int H = readInt(1, 1'000'000); readSpace(); int W = readInt(1, 4'000'000); if ((long long)H * W > 4'000'000) { fail("HxW violation"); } readEoln(); for (int i = 0; i < H; ++i) { readInt(0, 1'000'000'000); for (int j = 1; j < W; ++j) { readSpace(); readInt(0, 1'000'000'000); } readEoln(); } readEof(); }