diff options
author | Franciszek Malinka <franciszek.malinka@gmail.com> | 2021-03-07 17:58:54 +0100 |
---|---|---|
committer | Franciszek Malinka <franciszek.malinka@gmail.com> | 2021-03-07 17:58:54 +0100 |
commit | 647fafedf582a892db8b7f2c2858ad1bad3307db (patch) | |
tree | f158b279b1c09fea849b6dee136d6ab36b963407 /Semestr 4/aisd/Pracownia 1 | |
parent | 92cb85e139f150d4560e3ddd777732d2f94bf1df (diff) |
Aktualizacja
Diffstat (limited to 'Semestr 4/aisd/Pracownia 1')
-rw-r--r-- | Semestr 4/aisd/Pracownia 1/rozw2.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/Semestr 4/aisd/Pracownia 1/rozw2.cpp b/Semestr 4/aisd/Pracownia 1/rozw2.cpp new file mode 100644 index 0000000..35fd37e --- /dev/null +++ b/Semestr 4/aisd/Pracownia 1/rozw2.cpp @@ -0,0 +1,33 @@ +#include<bits/stdc++.h> +using namespace std; +typedef unsigned long long ll; + +vector<pair<int, ll>> v; + +int main() { + int n; + scanf("%d", &n); + for (int i = 0; i < n; i++) { + int d, nd, k = 0; + scanf("%d %d", &d, &nd); + while (d % 2 == 0) { + k++; + d /= 2; + } + v.push_back({d, (ll)(1LL<<k) * (ll)nd}); + } + sort(v.begin(), v.end()); + int result = 0; + for (int i = 0; i < n; ) { + int j = i; + int cur = v[i].first; + ll count = 0; + while (j < n && v[j].first == cur) { + count += v[j].second; + ++j; + } + result += __builtin_popcountll(count); + i = j; + } + cout << result << "\n"; +}
\ No newline at end of file |