#include <bits/stdc++.h> using namespace std; vector <vector<unsigned long long> >final_vector; vector<string>final_string_vector; template <typename T> std::string to_string(T value) { std::ostringstream os ; os << value ; return os.str() ; } void set_vector(vector<unsigned long long>&line,unsigned long long index,unsigned long long range,vector<pair<unsigned long long,unsigned long long> >v){ unsigned long long start, stop; long long a,b; a = index; b = range; //cout << "index/range -> "<<index<<"/"<<range<<endl; if(a-b<0){ start = 0; }else{ start = a-b; } if(a+b>line.size()-1){ stop = line.size()-1; }else{ stop = a+b; } //cout << "START/STOP ->"<<start<<"/"<<stop<<endl; for(unsigned long long i=start; i<=stop; ++i){ if(line[i]==1 && i!=index){ for(int j=0; j<v.size(); ++j){ if(v[j].first == i){ set_vector(line,i,v[j].second,v); } } //line[i]=0; } else{ line[i]=0; } } vector<unsigned long long>test; for(int i=0; i<v.size(); ++i){ if(line[v[i].first]==1){ test.push_back(1); }else{ test.push_back(0); } } final_vector.push_back(test); /* for(auto a:line){ cout << a << endl; } cout << endl; */ } int main() { vector<pair<unsigned long long,unsigned long long> >v; int n; cin >> n; for(int i=0; i<n; ++i){ unsigned long long a,r; cin >> a >> r; v.push_back(make_pair(a,r)); } vector<unsigned long long>line(v[v.size()-1].first+v[v.size()-1].second+1,0); for(int i=0; i<n; ++i){ line[v[i].first]=1; } for (unsigned long long len = 1; len <= v.size(); len++) { for (unsigned long long i = 0; i <= v.size() - len; i++) { for(int i=0; i<n; ++i){ line[v[i].first]=1; } unsigned long long j = i + len - 1; for (unsigned long long k = i; k <= j; k++){ set_vector(line,v[k].first,v[k].second,v); //cout << v[k].first<<endl; //cout << v[k].first; } } } for(int i=0; i<final_vector.size(); ++i){ string test = ""; for(int j=0; j<final_vector[i].size(); ++j){ int temp = final_vector[i][j]; test+=to_string(final_vector[i][j]); } final_string_vector.push_back(test); } /* cout << endl<< endl; for(auto a : final_string_vector){ cout << a << endl; } */ cout << set<string>(final_string_vector.begin(),final_string_vector.end()).size()+1; 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 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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | #include <bits/stdc++.h> using namespace std; vector <vector<unsigned long long> >final_vector; vector<string>final_string_vector; template <typename T> std::string to_string(T value) { std::ostringstream os ; os << value ; return os.str() ; } void set_vector(vector<unsigned long long>&line,unsigned long long index,unsigned long long range,vector<pair<unsigned long long,unsigned long long> >v){ unsigned long long start, stop; long long a,b; a = index; b = range; //cout << "index/range -> "<<index<<"/"<<range<<endl; if(a-b<0){ start = 0; }else{ start = a-b; } if(a+b>line.size()-1){ stop = line.size()-1; }else{ stop = a+b; } //cout << "START/STOP ->"<<start<<"/"<<stop<<endl; for(unsigned long long i=start; i<=stop; ++i){ if(line[i]==1 && i!=index){ for(int j=0; j<v.size(); ++j){ if(v[j].first == i){ set_vector(line,i,v[j].second,v); } } //line[i]=0; } else{ line[i]=0; } } vector<unsigned long long>test; for(int i=0; i<v.size(); ++i){ if(line[v[i].first]==1){ test.push_back(1); }else{ test.push_back(0); } } final_vector.push_back(test); /* for(auto a:line){ cout << a << endl; } cout << endl; */ } int main() { vector<pair<unsigned long long,unsigned long long> >v; int n; cin >> n; for(int i=0; i<n; ++i){ unsigned long long a,r; cin >> a >> r; v.push_back(make_pair(a,r)); } vector<unsigned long long>line(v[v.size()-1].first+v[v.size()-1].second+1,0); for(int i=0; i<n; ++i){ line[v[i].first]=1; } for (unsigned long long len = 1; len <= v.size(); len++) { for (unsigned long long i = 0; i <= v.size() - len; i++) { for(int i=0; i<n; ++i){ line[v[i].first]=1; } unsigned long long j = i + len - 1; for (unsigned long long k = i; k <= j; k++){ set_vector(line,v[k].first,v[k].second,v); //cout << v[k].first<<endl; //cout << v[k].first; } } } for(int i=0; i<final_vector.size(); ++i){ string test = ""; for(int j=0; j<final_vector[i].size(); ++j){ int temp = final_vector[i][j]; test+=to_string(final_vector[i][j]); } final_string_vector.push_back(test); } /* cout << endl<< endl; for(auto a : final_string_vector){ cout << a << endl; } */ cout << set<string>(final_string_vector.begin(),final_string_vector.end()).size()+1; return 0; } |