#include <iostream> #include <vector> #include <algorithm> #include <cmath> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int h,w,n; cin >> h >> w >> n; // vector<int> d; int last = 1; for (int i = 0; i < n; ++i) { int x; cin >> x; int nlast = x; x /= last; last = nlast; d.push_back(x); } // /*if (d[0] == 1) { vector< vector<unsigned char> > wall; for (int i = 0; i < h; i++) { vector<unsigned char> row; for (int j = 0; j < w; j++) { unsigned char place; place = 1; row.push_back(place); } wall.push_back(row); } }*/ int counter = -1; if (h%d[0] || w%d[0]) { cout << counter; return 0; } ++counter; for (size_t i = 0; i < d.size(); ++i) { //cout << "\ni[#]:" << i << "[" << d[i] << "]\told > w: " << w << " h: " << h << " counter: " << counter; counter += h % d[i] * w; counter += w % d[i] * ( h - (h % d[i]) ); h /= d[i]; w /= d[i]; //cout << "\tnew > w: " << w << " h: " << h << " counter: " << counter; if (w == 0 || h == 0) { break; } } counter += w * h; //cout << "\n\n\t"; cout << counter; //cout << "\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 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 | #include <iostream> #include <vector> #include <algorithm> #include <cmath> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int h,w,n; cin >> h >> w >> n; // vector<int> d; int last = 1; for (int i = 0; i < n; ++i) { int x; cin >> x; int nlast = x; x /= last; last = nlast; d.push_back(x); } // /*if (d[0] == 1) { vector< vector<unsigned char> > wall; for (int i = 0; i < h; i++) { vector<unsigned char> row; for (int j = 0; j < w; j++) { unsigned char place; place = 1; row.push_back(place); } wall.push_back(row); } }*/ int counter = -1; if (h%d[0] || w%d[0]) { cout << counter; return 0; } ++counter; for (size_t i = 0; i < d.size(); ++i) { //cout << "\ni[#]:" << i << "[" << d[i] << "]\told > w: " << w << " h: " << h << " counter: " << counter; counter += h % d[i] * w; counter += w % d[i] * ( h - (h % d[i]) ); h /= d[i]; w /= d[i]; //cout << "\tnew > w: " << w << " h: " << h << " counter: " << counter; if (w == 0 || h == 0) { break; } } counter += w * h; //cout << "\n\n\t"; cout << counter; //cout << "\n"; return 0; } |