#include<iostream> #include<vector> #include<algorithm> using namespace std; #define MAXN 300300 #define X 1000000007 struct item { long long suma; long long licznik; int parzyste; }; void print_item(item e) { cout << "ITEM: " << e.suma << ", " << e.licznik << ", " << e.parzyste << endl; } int main() { int n; vector<long long> v; cin >> n; //cout << "CZYTAMY DANE" << endl; for (int i = 0; i < n; i++) { int input; cin >> input; v.push_back(input); } vector<item> items0; vector<item> items1; vector<item> *prev = &items0; vector<item> *next = &items1; items0.push_back(item()); items0.back().suma = v[0]; items0.back().licznik = 1; if (v[0] % 2 == 0) items0.back().parzyste = 1; else items0.back().parzyste = 0; //cout << "========================= ITERATION 0 =============================" << endl; //for (vector<item>::iterator iter = prev->begin(); iter != prev->end(); iter++) { // cout << iter->suma << ", " << iter->licznik << ", " << iter->parzyste << endl; //} for (int i = 1; i < n; ++i) { //cout << "========================= ITERATION " << i << " =============================" << endl; long long singleton_count = 0; for(vector<item>::iterator iter = prev->begin(); iter != prev->end(); iter++) { //cout << "ODWIEDZAMY "; //print_item(*iter); if (iter->parzyste == 1) { singleton_count += iter->licznik; next->push_back(item()); next->back().suma = (v[i] + iter->suma) % X; next->back().licznik = iter->licznik; next->back().parzyste = (next->back().suma % 2) == 0; //cout << " DOKŁADAMY "; //print_item(next->back()); } else { next->push_back(item()); next->back().suma = (v[i] + iter->suma) % X; next->back().licznik = iter->licznik; next->back().parzyste = (next->back().suma % 2) == 0; //cout << " DOKŁADAMY "; //print_item(next->back()); } } if (singleton_count > 0) { //cout << "DOKŁADAMY SINGLETON "; next->push_back(item()); next->back().suma = v[i]; next->back().licznik = singleton_count % X; next->back().parzyste = (v[i] % 2) == 0; //print_item(next->back()); } //for (vector<item>::iterator iter = next->begin(); iter != next->end(); iter++) { // cout << iter->suma << ", " << iter->licznik << ", " << iter->parzyste << endl; //} prev->clear(); vector<item> *tmp = prev; prev = next; next = tmp; } vector<item> *toCheck; if (!prev->empty()) toCheck = prev; else toCheck = next; //cout << "+++++++++++++ RESULT +++++++++++++++++++++" << endl; long long sum = 0; for (vector<item>::iterator iter = prev->begin(); iter != prev->end(); iter++) { if (iter->parzyste == 1) sum = (sum + iter->licznik) % X; //cout << iter->suma << ", " << iter->licznik << ", " << iter->parzyste << endl; } cout << sum << 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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | #include<iostream> #include<vector> #include<algorithm> using namespace std; #define MAXN 300300 #define X 1000000007 struct item { long long suma; long long licznik; int parzyste; }; void print_item(item e) { cout << "ITEM: " << e.suma << ", " << e.licznik << ", " << e.parzyste << endl; } int main() { int n; vector<long long> v; cin >> n; //cout << "CZYTAMY DANE" << endl; for (int i = 0; i < n; i++) { int input; cin >> input; v.push_back(input); } vector<item> items0; vector<item> items1; vector<item> *prev = &items0; vector<item> *next = &items1; items0.push_back(item()); items0.back().suma = v[0]; items0.back().licznik = 1; if (v[0] % 2 == 0) items0.back().parzyste = 1; else items0.back().parzyste = 0; //cout << "========================= ITERATION 0 =============================" << endl; //for (vector<item>::iterator iter = prev->begin(); iter != prev->end(); iter++) { // cout << iter->suma << ", " << iter->licznik << ", " << iter->parzyste << endl; //} for (int i = 1; i < n; ++i) { //cout << "========================= ITERATION " << i << " =============================" << endl; long long singleton_count = 0; for(vector<item>::iterator iter = prev->begin(); iter != prev->end(); iter++) { //cout << "ODWIEDZAMY "; //print_item(*iter); if (iter->parzyste == 1) { singleton_count += iter->licznik; next->push_back(item()); next->back().suma = (v[i] + iter->suma) % X; next->back().licznik = iter->licznik; next->back().parzyste = (next->back().suma % 2) == 0; //cout << " DOKŁADAMY "; //print_item(next->back()); } else { next->push_back(item()); next->back().suma = (v[i] + iter->suma) % X; next->back().licznik = iter->licznik; next->back().parzyste = (next->back().suma % 2) == 0; //cout << " DOKŁADAMY "; //print_item(next->back()); } } if (singleton_count > 0) { //cout << "DOKŁADAMY SINGLETON "; next->push_back(item()); next->back().suma = v[i]; next->back().licznik = singleton_count % X; next->back().parzyste = (v[i] % 2) == 0; //print_item(next->back()); } //for (vector<item>::iterator iter = next->begin(); iter != next->end(); iter++) { // cout << iter->suma << ", " << iter->licznik << ", " << iter->parzyste << endl; //} prev->clear(); vector<item> *tmp = prev; prev = next; next = tmp; } vector<item> *toCheck; if (!prev->empty()) toCheck = prev; else toCheck = next; //cout << "+++++++++++++ RESULT +++++++++++++++++++++" << endl; long long sum = 0; for (vector<item>::iterator iter = prev->begin(); iter != prev->end(); iter++) { if (iter->parzyste == 1) sum = (sum + iter->licznik) % X; //cout << iter->suma << ", " << iter->licznik << ", " << iter->parzyste << endl; } cout << sum << endl; } |