#include #include #include #include #include "validate.h" using namespace std; // Reads the input file and returns a bitset `visited` such // that `visited[i]` is true iff the given route traverses the // longitude band between `i-180` degrees and `i-179` degrees. bitset<360> simulate_route() { int n; judge_in >> n; vector lat(n+1), lon(n+1); for (int i = 0; i < n; i++) { judge_in >> lat[i] >> lon[i]; } lat[n] = lat[0], lon[n] = lon[0]; bitset<360> visited; // Marks off the band with longitude `lon1` as the western bound // and longitude `lon2` as the eastern bound as visited. auto travel = [&](int lon1, int lon2) { while (lon1 != lon2) { visited[lon1+180] = true; if (++lon1 == 180) lon1 = -180; } }; for (int i = 0; i < n; i++) { int dist = (lon[i+1]-lon[i]+360) % 360; // change of longitude if (dist < 180) { travel(lon[i], lon[i+1]); // flying east } else if (dist > 180) { travel(lon[i+1], lon[i]); // flying west } else { visited.set(); // flying over one of the poles } } return visited; } int main(int argc, char **argv) { init_io(argc,argv); bitset<360> visited = simulate_route(); string author_ans; if (!(author_out >> author_ans)) { wrong_answer("Wrong answer: expected 'yes' or 'no'.\n"); } transform(begin(author_ans), end(author_ans), begin(author_ans), [](char c) { return tolower(c); }); if (author_ans == "yes") { if (!visited.all()) { wrong_answer("Wrong answer: expected 'no', got 'yes'.\n"); } } else if (author_ans == "no") { if (visited.all()) { wrong_answer("Wrong answer: expected 'yes', got 'no'.\n"); } int lon; char separator; string dec; author_out >> ws; bool has_minus = author_out.peek() == '-'; if (!(author_out >> lon >> separator >> dec)) { wrong_answer("Wrong answer: expected a real number written with decimal part.\n"); } if(!(dec == "0" || dec == "5") || separator != '.') { wrong_answer("Wrong answer: expected a . as a decimal separator, " "followed by a single 0 or a single 5."); } if (lon < -180 || lon >= 180) { wrong_answer("Wrong answer: longitude out of range, must be in [-180,180).\n"); } if (dec == "0" && (visited[180 + lon] or visited[(179 + lon + 360) % 360])) { wrong_answer("Wrong answer: the route passes through the given meridian.\n"); } if (dec == "5" && ((!has_minus && visited[180 + lon]) || (has_minus && visited[(179 + lon + 360) % 360]))) { wrong_answer("Wrong answer: the route passes through the given meridian.\n"); } } else { wrong_answer("Wrong answer: expected 'yes' or 'no'.\n"); } string junk; if (author_out >> junk) { wrong_answer("Wrong answer: found trailing output.\n"); } accept(); }