#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define int long long
using namespace std;
vector<int> odl;
int n, a, r, ile=1, gdzie[300009], poz[300009], zasieg[300009], wynik=1, mod=1000000007;
map<set<int>, int> mapa;
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
cin>>n;
for(int i=0; i<n; i++){
cin>>a>>r;
gdzie[i]=a;
zasieg[i]=r;
ile*=2;
}
for(int i=1; i<ile; i++){
bitset<300009> bity(i);
bitset<300009> odw;
set<int> s;
queue<int> q;
for(int j=0; j<n; j++){
if(bity[j]){
q.push(j);
odw[j]=1;
}
}
while(!q.empty()){
int x=q.front();
q.pop();
s.insert(x);
for(int ind=0; ind<n; ind++){
if(gdzie[ind]>=gdzie[x]-zasieg[x]&& gdzie[ind]<=gdzie[x]+zasieg[x]&&!odw[ind]){
q.push(ind);
odw[ind]=1;
}
}
}
if(!mapa[s]){
mapa[s]=1;
wynik=(wynik+1)%mod;
}
}
cout<<wynik<<"\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 48 49 50 51 | #include<bits/stdc++.h> #define mp make_pair #define pb push_back #define int long long using namespace std; vector<int> odl; int n, a, r, ile=1, gdzie[300009], poz[300009], zasieg[300009], wynik=1, mod=1000000007; map<set<int>, int> mapa; int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); cin>>n; for(int i=0; i<n; i++){ cin>>a>>r; gdzie[i]=a; zasieg[i]=r; ile*=2; } for(int i=1; i<ile; i++){ bitset<300009> bity(i); bitset<300009> odw; set<int> s; queue<int> q; for(int j=0; j<n; j++){ if(bity[j]){ q.push(j); odw[j]=1; } } while(!q.empty()){ int x=q.front(); q.pop(); s.insert(x); for(int ind=0; ind<n; ind++){ if(gdzie[ind]>=gdzie[x]-zasieg[x]&& gdzie[ind]<=gdzie[x]+zasieg[x]&&!odw[ind]){ q.push(ind); odw[ind]=1; } } } if(!mapa[s]){ mapa[s]=1; wynik=(wynik+1)%mod; } } cout<<wynik<<"\n"; return 0; } |
English