```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 ``` ```// And equation solver // For more details please check Topcoder SRM#545 Div II easy (250) question #include #include #include #include #include using namespace std; static int arr_0[] = {1, 3, 5}; static int arr_1[] = {31, 7}; static int arr_2[] = {31, 7, 7}; static int arr_3[] = {1,0,0,1,0,1,0,1,0,0,0,0,0,0,0,1,0,0, 0,0,0,0,0,0,1,0,1,0,1,1,0,0,0,1}; static int arr_4[] = {191411,256951,191411, 191411,191411,256951,195507,191411,192435,191411, 191411,195511,191419,191411,256947,191415,191475,195579,191415,191411, 191483,191411,191419,191475,256947,191411,191411,191411,191419,256947, 191411,191411,191411}; static int arr_5[] = {1362,1066,1659,2010,1912,1720,1851,1593,1799,1805,1139,1493,1141,1163,1211}; static int arr_6[] = {2, 3, 7, 19}; int restoreY(const int *arr, int sz) { const int *const e = arr + sz; const int *const can = std::min_element( arr, e); int val = INT_MAX; for(const int *it = arr; it != e; ++it) { if(it == can) continue; // If you wanna avoid this check // or use std::accumulate(), set // *can = INT_MAX temporarily :) val &= *it; } if(*can == val) return *can; return -1; } #define GENERATE_TEST_CASE(id,expected) void test_##id() { \ int *a = arr_##id; \ const int arrsize = static_cast( sizeof arr_##id / sizeof arr_##id[0]); \ const int actual = restoreY(a, arrsize); \ cout << "Test case #" << id << ": "; \ if(actual == expected) cout << "Passed" << endl; \ else { \ cout << "Failed, expected = " << expected \ << ", actual " << actual << endl; \ } \ } GENERATE_TEST_CASE(0, 1) GENERATE_TEST_CASE(1, -1) GENERATE_TEST_CASE(2, 7) GENERATE_TEST_CASE(3, 0) GENERATE_TEST_CASE(4, 191411) GENERATE_TEST_CASE(5, -1) GENERATE_TEST_CASE(6, -1) int main() { #define RUN_TEST_CASE(id) test_##id() RUN_TEST_CASE(0); RUN_TEST_CASE(1); RUN_TEST_CASE(2); RUN_TEST_CASE(3); RUN_TEST_CASE(4); RUN_TEST_CASE(5); RUN_TEST_CASE(6); } ```
 ```1 2 3 4 5 6 7 ``` ```Test case #0: Passed Test case #1: Passed Test case #2: Passed Test case #3: Passed Test case #4: Passed Test case #5: Passed Test case #6: Passed ```