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
52
53
54
55
#include <iostream>
#include <vector>
#include <stack>
#include <cmath>

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector< vector<int> > G(n);
    vector<ll> a(n), r(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i] >> r[i];
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            if (i != j && abs(a[i] - a[j]) <= r[i])
                G[i].push_back(j);
    vector< vector<bool> > odw(n, vector<bool>(n, false));
    for (int i = 0; i < n; ++i)
    {
        stack<int> S;
        odw[i][i] = true;
        S.push(i);
        while (!S.empty())
        {
            int akt = S.top();
            S.pop();
            for (int j = 0; j < G[akt].size(); ++j)
            {
                if (!odw[i][G[akt][j]])
                {
                    odw[i][G[akt][j]] = true;
                    S.push(G[akt][j]);
                }
            }
        }
    }
    int odp = 0;
    for (int mask = 0; mask < (1 << n); ++mask)
    {
        bool ok = true;
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < n; ++j)
                if ((mask & (1 << i)) > 0 && (mask & (1 << j)) == 0 && odw[i][j])
                    ok = false;
        odp += ok;
    }
    cout << odp;
    return 0;
}