Submission #385039

#TimeUsernameProblemLanguageResultExecution timeMemory
385039thecodingwizardČVENK (COI15_cvenk)C++11
17 / 100
35 ms5992 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define ii pair<ll, ll> #define f first #define s second #define pb push_back #define mp make_pair #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() #define F0R(i, n) for (int i = 0; i < n; i++) #define FOR(i, a, b) for (int i = a; i < b; i++) #define inf 1000000010 vector<ii> A; void clean() { for (int i = 30; ~i; i--) { bool allF = 1; for (auto x : A) { if (!(x.f & (1 << i))) allF = 0; } bool allS = 1; for (auto x : A) { if (!(x.s & (1 << i))) allS = 0; } bool any = 0; for (auto x : A) { if (x.f & (1 << i)) any = 1; if (x.s & (1 << i)) any = 1; } if (allF) { for (auto &x : A) { x.f ^= (1 << i); } } else if (allS) { for (auto &x : A) { x.s ^= (1 << i); } } else if (any) { break; } } } // true if left, false if up // second number is distance from that axis pair<bool, ll> calc(ii x) { int dir = -1; ll dist = 0; for (int i = 30; ~i; i--) { int curDir = -1; if (x.f & (1 << i)) { curDir = 1; } else if (x.s & (1 << i)) { curDir = 0; } if (dir == -1) dir = curDir; if (curDir != -1 && curDir != dir) break; if (curDir != -1) dist += (1 << i); } return make_pair(dir, dist); } int main() { cin.tie(0)->sync_with_stdio(0); int n; cin >> n; A.resize(n); F0R(i, n) cin >> A[i].f >> A[i].s; clean(); vector<pair<bool, ll>> res; for (auto x : A) res.push_back(calc(x)); //for (auto x : A) cout << x.f << " " << x.s << endl; ll totSum = 0; for (auto x : A) totSum += x.f + x.s; bool allSame = 1; for (auto x : res) { if (x.f != res[0].f) allSame = 0; } if (allSame) { ll minDist = 1e18; for (auto x : res) minDist = min(minDist, x.s); cout << totSum - (ll)n*minDist << endl; } else { cout << totSum << endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...