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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 #include #include #include #include #include #include #define MOD 1000000007LL typedef unsigned long long num; using namespace std; char *hyper_cube; struct Sphere { string start; int r; }; int64_t fastPow(int64_t a, int64_t exp, int64_t mod) { int64_t res = 1; while (exp) { if (exp % 2 == 1) { res *= a; res %= mod; } a *= a; a %= mod; exp >>= 1; } return res; } // This inverse works only for primes p, it uses Fermat's little theorem int64_t inverse(int64_t a, int64_t p) { return fastPow(a, p - 2, p); } int64_t bc(int64_t n, int64_t k, int64_t p=MOD) { std::vector fact(n + 1); fact[0] = 1; for (auto i = 1; i <= n; ++i) fact[i] = (fact[i - 1] * i) % p; return ((((fact[n] * inverse(fact[k], p)) % p) * inverse(fact[n - k], p)) % p); } void mark_range(int position, int r, int &n, int &index) { if (r < 0) { return; } hyper_cube[position] = index; for (int i = 0; i < n; i++) { mark_range(position ^ (1 << i), r - 1, n, index); } } int brute_force(vector &spheres, int &n) { int result = 0; hyper_cube = new char[1< &spheres, unsigned long long &n) { unsigned long long result = 0; vector spheres_int_starts(spheres.size()); for(int i=0; i &spheres, unsigned long long &n) { unsigned long long result = 0; for (int i=0; i spheres(3); scanf("%lld", &n); for (int i=0; i<3; i++) { cin >> spheres[i].r >> spheres[i].start; } if (spheres.size() == 3 && spheres[0].start == spheres[1].start) { if (spheres[0].r > spheres[1].r) { spheres.erase(spheres.begin() + 1); } else { spheres.erase(spheres.begin()); } } if (spheres.size() == 3 && spheres[0].start == spheres[2].start) { if (spheres[0].r > spheres[2].r) { spheres.erase(spheres.begin() + 2); } else { spheres.erase(spheres.begin()); } } if (spheres.size() == 3 && spheres[1].start == spheres[2].start) { if (spheres[1].r > spheres[2].r) { spheres.erase(spheres.begin() + 2); } else { spheres.erase(spheres.begin() + 1); } } printf("%lld\n", brute_force2(spheres, n)); }