Submission #477365

#TimeUsernameProblemLanguageResultExecution timeMemory
477365BTheroCutting a rectangle (LMIO18_staciakampis)C++17
0 / 100
1076 ms1524 KiB
#include <bits/stdc++.h> #define pb push_back #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() using namespace std; typedef long long ll; set<vector<pair<int, int>>> S; set<int> T; void go(vector<pair<int, int>> vec) { for (int i = 0; i < sz(vec); i++) { if (vec[i].first < vec[i].second) { swap(vec[i].first, vec[i].second); } } sort(all(vec)); if (S.insert(vec).second == 0) { return; } if (sz(vec) == 1) { T.insert(vec[0].second); return; } for (int a = 0; a < sz(vec); a++) { if (a + 1 < sz(vec) && vec[a].first == vec[a + 1].first) { vector<pair<int, int>> new_vec = vec; new_vec.erase(new_vec.begin() + a); new_vec.erase(new_vec.begin() + a); new_vec.pb({vec[a].first, vec[a].second + vec[a + 1].second}); go(new_vec); } for (int b = a + 1; b < sz(vec); b++) { if (vec[a].first == vec[b].second) { vector<pair<int, int>> new_vec = vec; new_vec.erase(new_vec.begin() + b); new_vec.erase(new_vec.begin() + a); new_vec.pb({vec[a].first, vec[a].second + vec[b].first}); go(new_vec); } if (vec[a].second == vec[b].second) { vector<pair<int, int>> new_vec = vec; new_vec.erase(new_vec.begin() + b); new_vec.erase(new_vec.begin() + a); new_vec.pb({vec[a].first + vec[b].first, vec[a].second}); go(new_vec); } } } } int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<pair<int, int>> a(n); ll sum = 0; for (int i = 0; i < n; i++) { cin >> a[i].first >> a[i].second; sum += a[i].first * 1ll * a[i].second; } if (n <= 10 && 0) { go(a); } else { auto check = [&](ll w, ll h) -> bool { vector<int> was(n, 0); int alive = n; bool changed = 1; while (alive && changed) { if (w < h) { swap(w, h); } changed = 0; for (int i = n - 1; ~i; i--) { if (!was[i] && a[i].first == w) { h -= a[i].second; was[i] = 1; --alive; changed = 1; } if (!was[i] && a[i].first == h) { w -= a[i].second; was[i] = 1; --alive; changed = 1; } } for (int i = n - 1; ~i; i--) { if (!was[i] && a[i].second == w) { h -= a[i].first; was[i] = 1; --alive; changed = 1; } if (!was[i] && a[i].second == h) { w -= a[i].second; was[i] = 1; --alive; changed = 1; } } } return alive == 0; }; for (ll d = 1; d * d <= sum; d++) { if (sum % d == 0) { if (check(d, sum / d)) T.insert(d); } } } cout << sz(T) << '\n'; for (int x : T) { cout << x << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...