Untitled
unknown
plain_text
2 years ago
2.0 kB
232
Indexable
#define fst first
#define snd second
#define MP make_pair
#define FOR(i, n) for (int i = 0; i < n; i++)
#define FORL(i, m, n) for (int i = m; i < n; i++)
#define FORV(i, v) for (int i = 0; i < v.size(); i++)
struct Hail {
int id;
LL x, y, z, a, b, c;
};
vector<LL> Primes(LL n) {
vector<LL> ret;
bool done = false;
while (!done) {
done = true;
LL stop = sqrt(n);
for (LL i = 2; i <= stop; i++) {
if (n % i == 0) {
ret.push_back(i);
n /= i;
done = false;
break;
}
}
}
ret.push_back(n);
return ret;
}
int main() {
// After running the code below, searched for vx = 99, vy = 240, vz = 188 in the input:
LL xx = 231279746486542LL;
LL yy = 131907658181641LL;
LL zz = 195227847662645LL;
cout << xx + yy + zz << endl;
return 0;
vector<string> lines = ReadInput(); // ctrl-Z to terminate
vector<Hail> hs;
FORV(i, lines) {
StrTok st(lines[i], " @ ");
StrTok st1(st.Next(), ", ");
LL x = FromString<LL>(st1.Next());
LL y = FromString<LL>(st1.Next());
LL z = FromString<LL>(st1.Next());
StrTok st2(st.Next(), ", ");
LL vx = FromString<LL>(st2.Next());
LL vy = FromString<LL>(st2.Next());
LL vz = FromString<LL>(st2.Next());
Hail h;
h.id = i;
h.x = x;
h.y = y;
h.z = z;
h.a = vx;
h.b = vy;
h.c = vz;
hs.push_back(h);
}
// Code for finding out that vz = 188
// Same strategy works for finding vx and vy
map<LL, vector<Hail>> m;
for (Hail h : hs) m[h.c].push_back(move(h));
for (auto& elt : m) {
if (elt.snd.size() < 2) continue;
vector<Hail>& v = elt.snd;
sort(v.begin(), v.end(), [](const Hail& h1, const Hail& h2) { return h1.z > h2.z; });
FORV(i, v) {
FORL(j, i + 1, v.size()) {
vector<LL> ps = Primes(v[i].z - v[j].z);
cout << v[i].id << " " << v[j].id;
cout << " (" << v[i].c << "): ";
FORV(k, ps) cout << ps[k] << " ";
cout << endl;
}
}
}
return 0;
}Editor is loading...
Leave a Comment