#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
const int N = 3e5 + 7, M = 5e6 + 7, mod = 1e9 + 7;
int n;
pair<int, int> p[N];
multiset<int> ga[M], gb[M];
void solve() {
cin>>n;
int area = 0;
for(int i = 1; i <= n; i++) {
cin>>p[i].fi>>p[i].se;
area = area + p[i].fi * p[i].se;
}
vector<int> ans;
for(int i = 1; i <= 5e6; i++) {
if(area % i == 0 && i <= area / i) {
int x = area / i, y = i;
vector<int> us(n + 1, 0);
for(int j = 1; j <= n; j++) {
ga[p[j].fi].clear();
gb[p[j].se].clear();
}
for(int j = 1; j <= n; j++) {
ga[p[j].fi].insert(j);
gb[p[j].se].insert(j);
}
while(x && y) {
if(x < y)swap(x, y);
int ok = 0;
if(x <= 5e6) {
for(auto i : ga[x]) {
if(!us[i]) {
us[i] = 1;
y -= p[i].se;
ok = i;
break;
}
}
}
if(ok) {
ga[p[ok].fi].erase(ga[p[ok].fi].find(ok));
gb[p[ok].se].erase(gb[p[ok].se].find(ok));
continue;
}
for(auto i : gb[y]) {
if(!us[i]) {
us[i] = 1;
x -= p[i].fi;
ok = i;
break;
}
}
if(ok) {
ga[p[ok].fi].erase(ga[p[ok].fi].find(ok));
gb[p[ok].se].erase(gb[p[ok].se].find(ok));
continue;
}
if(x <= 5e6) {
for(auto i : gb[x]) {
if(!us[i]) {
us[i] = 1;
y -= p[i].fi;
ok = i;
break;
}
}
}
if(ok) {
ga[p[ok].fi].erase(ga[p[ok].fi].find(ok));
gb[p[ok].se].erase(gb[p[ok].se].find(ok));
continue;
}
for(auto i : ga[y]) {
if(!us[i]) {
us[i] = 1;
x -= p[i].se;
ok = i;
break;
}
}
if(ok) {
ga[p[ok].fi].erase(ga[p[ok].fi].find(ok));
gb[p[ok].se].erase(gb[p[ok].se].find(ok));
continue;
}else break;
}
bool ok = 1;
for(int j = 1; j <= n; j++)
if(!us[j])ok = 0;
if((!x || !y) && ok)ans.push_back(i);
}
}
cout << ans.size() << '\n';
for(auto i : ans)cout << i << '\n';
}
signed main() {
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
int T = 1;
// cin>>T;
while(T --)solve();
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |