/// Radoslaw Mysliwiec 2020 #pragma GCC optimize("O3") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define F first #define S second #define PB push_back #define ALL(x) (x).begin(),(x).end() #define endl '\n' #define dd cout << " debug"; using ll = long long; using ld = long double; using vi = vector<int>; using vll = vector<ll>; using pi = pair<int,int>; using pll = pair<ll,ll>; using matrix = vector<vll>; using ordered_set = tree<pi, null_type, less<pi>, rb_tree_tag, tree_order_statistics_node_update>; ll pos[300300], radius[300300], r[300300], l[300300], n; vector<bool> done(100000000, 0); int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i=0; i<n; ++i){ cin >> pos[i] >> radius[i]; } int x, res = 0; for (int i=0; i<(1<<n); ++i) { x = 0; for (int j=0; j<n; ++j) { if ((i>>j) & 1) { l[j] = pos[j] - radius[j]; r[j] = pos[j] + radius[j]; int L = j, R = j; while (L >= 0 || R < n) { bool change = 0; if (L >= 0 && l[j] <= pos[L]) { x |= (1<<L); l[j] = min(l[j], pos[L] - radius[L]); r[j] = max(r[j], pos[L] + radius[L]); --L; change = 1; } if (R < n && r[j] >= pos[R]) { x |= (1<<R); l[j] = min(l[j], pos[R] - radius[R]); r[j] = max(r[j], pos[R] + radius[R]); ++R; change = 1; } if (change == 0) break; } } } if (!done[x]) { ++res; done[x] = true; /* cout << "{"; vi result; for (int i=1; i<=n; ++i){ if ((x>>(i-1))&1) result.PB(i); } for (int i=0; i<result.size(); ++i) { if (i == 0) cout << result[i]; else cout << ", " << result[i]; } cout << "}\n";*/ } } cout << res << endl; }
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | /// Radoslaw Mysliwiec 2020 #pragma GCC optimize("O3") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define F first #define S second #define PB push_back #define ALL(x) (x).begin(),(x).end() #define endl '\n' #define dd cout << " debug"; using ll = long long; using ld = long double; using vi = vector<int>; using vll = vector<ll>; using pi = pair<int,int>; using pll = pair<ll,ll>; using matrix = vector<vll>; using ordered_set = tree<pi, null_type, less<pi>, rb_tree_tag, tree_order_statistics_node_update>; ll pos[300300], radius[300300], r[300300], l[300300], n; vector<bool> done(100000000, 0); int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i=0; i<n; ++i){ cin >> pos[i] >> radius[i]; } int x, res = 0; for (int i=0; i<(1<<n); ++i) { x = 0; for (int j=0; j<n; ++j) { if ((i>>j) & 1) { l[j] = pos[j] - radius[j]; r[j] = pos[j] + radius[j]; int L = j, R = j; while (L >= 0 || R < n) { bool change = 0; if (L >= 0 && l[j] <= pos[L]) { x |= (1<<L); l[j] = min(l[j], pos[L] - radius[L]); r[j] = max(r[j], pos[L] + radius[L]); --L; change = 1; } if (R < n && r[j] >= pos[R]) { x |= (1<<R); l[j] = min(l[j], pos[R] - radius[R]); r[j] = max(r[j], pos[R] + radius[R]); ++R; change = 1; } if (change == 0) break; } } } if (!done[x]) { ++res; done[x] = true; /* cout << "{"; vi result; for (int i=1; i<=n; ++i){ if ((x>>(i-1))&1) result.PB(i); } for (int i=0; i<result.size(); ++i) { if (i == 0) cout << result[i]; else cout << ", " << result[i]; } cout << "}\n";*/ } } cout << res << endl; } |