Dear all, I'm unable to get the output pass Test Set 2, even if it passed my own validation.
I would appreciate if anyone can point out what's my mistake, especially those in my validator code. Thanks! Regards, WC Leung. // Compile with MinGW-64 in MSYS2 #include <stdint.h> #include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <string> #include <queue> #include <unordered_set> #include <vector> using namespace std; vector<pair<int, int>> result; void build2(int cols, int startrow) { for (int i = 0; i < 2; ++i) { int r = i; int c = 0; for (int j = 0; j < cols; ++j) { result.emplace_back(r+1+startrow, c+1); c += 2; c %= cols; if (c == 0) c = 1; r += 1; r %= 2; } } } void build3(int cols, int startrow) { if (cols % 3 == 0) { for (int i = 0; i < cols; ++i) { int r = 0; int c = i; for (int j = 0; j < 3; ++j) { result.emplace_back(r+1+startrow, c+1); c += 2; c %= cols; r += 1; r %= 3; } } } else { int r = 0; int c = 0; for (int i = 0; i < cols; ++i) { for (int j = 0; j < 3; ++j) { result.emplace_back(r+1+startrow, c+1); c += 2; c %= cols; r += 1; r %= 3; } c += (cols - 3); c %= cols; } } } void build4(int rows) { vector<int> start = {3, 0, 1, 2}; for (int c : start) { for (int r = 0; r < rows; ++r) { result.emplace_back(r+1, c+1); c += 2; c %= 4; } } } void solve(int caseNo) { std::cout << "Case #" << caseNo << ": "; int rows, cols; cin >> rows >> cols; bool reverse = rows > cols; if (reverse) swap(rows, cols); int length = cols; int width = rows; if (width == 1 && length == 1) { cout << "POSSIBLE\n1 1\n"; return; } else if (width == 1 || (width == 2 && length <= 4) || (width == 3 && length < 4)) { cout << "IMPOSSIBLE\n"; return; } result.clear(); cout << "POSSIBLE\n"; if (cols == 4) { build4(rows); } else { for (int r = 0; r < rows; r += 2) { if (rows - r == 3) { build3(cols, r); break; } build2(cols, r); } } unordered_set<int> played; pair<int, int> prev{-1000, -1}; for (pair<int, int> item : result) { if (item.first < 1 || item.first > rows || item.second < 1 || item.second > cols) { cerr << "out of range: " << rows << " " << cols << '\n'; break; } if (reverse) swap(item.first, item.second); int num = item.first * 100 + item.second; if (played.count(num) == 1) { cerr << "repeat!" << rows << " " << cols << '\n'; break; } played.insert(num); if (item.first == prev.first || item.second == prev.second || item.first + item.second == prev.first + prev.second || item.first - item.second == prev.first - prev.second) { cerr << "bad play: " << rows << " " << cols << '\n'; break; } cout << item.first << ' ' << item.second << '\n'; } cerr << '#'; if ((reverse ? rows : cols) == 20) cerr << '\n'; } int main(int argc, char** argv) { int N; std::cin >> N; std::string str; std::getline(std::cin, str); for (int i = 0; i < N; ++i) { solve(i + 1); } return 0; } -- You received this message because you are subscribed to the Google Groups "Google Code Jam" group. To unsubscribe from this group and stop receiving emails from it, send an email to google-code+unsubscr...@googlegroups.com. To post to this group, send email to google-code@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/google-code/5abf6694-2acd-4288-b016-65e06ce32efe%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.