This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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);
for (int i = 0; i < n; i++) {
cin >> a[i].first >> a[i].second;
}
if (n <= 10) {
go(a);
cout << sz(T) << '\n';
for (int x : T) {
cout << x << '\n';
}
}
else {
ll sum = 0;
int mx = 0;
for (int i = 0; i < n; i++) {
sum += a[i].first;
mx = max(mx, a[i].first);
}
for (ll d = 1; d * d <= sum; d++) {
if (sum % d == 0) {
if (d >= mx || sum / d >= mx) T.insert(d);
}
}
cout << sz(T) << '\n';
for (ll x : T) {
cout << x << '\n';
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |