#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
size_t n;
cin >> n;
vector<long long> odpala[n];
map<long long, size_t> miny_wstecz; // coord, index
set<pair<long long, size_t>> pole_razenia; // coord, index
for(size_t i = 0; i < n; ++i) {
long long a, r;
cin >> a >> r;
for(auto it = pole_razenia.lower_bound({a, 0}); it != pole_razenia.end();
++it) // wszystkie, które nas obejmują
odpala[it->second].push_back(i);
for(auto it = miny_wstecz.lower_bound(a - r); it != miny_wstecz.end();
++it) // wszystkie, które my obejmujemy
odpala[i].push_back(it->second);
pole_razenia.insert({a + r, i});
miny_wstecz[a] = i;
}
unsigned long long x;
unsigned long long end = 1 << n;
unsigned long long s = 1;
for(unsigned long long c = 1; c && (c < end); ++c) {
bool failed = false;
for(size_t i = 0; i < n; ++i) {
if(c & (1 << i)) {
for(auto e : odpala[i]) {
if(!(c & (1 << e))){
failed = true;
break;
}
}
}
if(failed)
break;
}
if(!failed)
++s;
}
cout << s%1000000007 << '\n';
return 0;
}
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 | #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); size_t n; cin >> n; vector<long long> odpala[n]; map<long long, size_t> miny_wstecz; // coord, index set<pair<long long, size_t>> pole_razenia; // coord, index for(size_t i = 0; i < n; ++i) { long long a, r; cin >> a >> r; for(auto it = pole_razenia.lower_bound({a, 0}); it != pole_razenia.end(); ++it) // wszystkie, które nas obejmują odpala[it->second].push_back(i); for(auto it = miny_wstecz.lower_bound(a - r); it != miny_wstecz.end(); ++it) // wszystkie, które my obejmujemy odpala[i].push_back(it->second); pole_razenia.insert({a + r, i}); miny_wstecz[a] = i; } unsigned long long x; unsigned long long end = 1 << n; unsigned long long s = 1; for(unsigned long long c = 1; c && (c < end); ++c) { bool failed = false; for(size_t i = 0; i < n; ++i) { if(c & (1 << i)) { for(auto e : odpala[i]) { if(!(c & (1 << e))){ failed = true; break; } } } if(failed) break; } if(!failed) ++s; } cout << s%1000000007 << '\n'; return 0; } |
English