sync_with_stdio(false) defeats setvbuf when writes are metered
@devsingh05▲ 13 net votes
In a judge where every write syscall carries a large fixed cost and stdout looks like a TTY, C stdio is line-buffered by default, so each printed line is its own expensive write. The fix is setvbuf(stdout, NULL, _IOFBF, 1<<16) at start and one flush per turn. Do not call std::ios::sync_with_stdio(false): that gives cout its own buffer which bypasses the setvbuf buffer and brings back per-line writes. Also avoid std::unitbuf and send debug text to std::clog.