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>
using namespace std;
#define int long long
#define ll long long
#define ii pair<int,int>
#define iii tuple<int,int,int>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << ": " << x << endl
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define rep(x,start,end) for(int x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
int n;
ii arr[100005];
bool has[100005];
vector<int> B[5000005];
vector<int> S[5000005];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin.exceptions(ios::badbit | ios::failbit);
cin>>n;
rep(x,1,n+1) cin>>arr[x].fi>>arr[x].se;
int sum=0;
rep(x,1,n+1) sum+=arr[x].fi*arr[x].se;
vector<int> ans;
rep(l,1,5000005) if (sum%l==0 && l<=sum/l){
int a=l,b=sum/l;
rep(x,1,n+1){
has[x]=false;
B[arr[x].fi].clear();
S[arr[x].se].clear();
}
rep(x,1,n+1){
B[arr[x].fi].pub(x);
S[arr[x].se].pub(x);
}
while (true){
if (a<b) swap(a,b);
bool h=false;
if (a<5000005) for (auto it:B[a]) if (!has[it]){
has[it]=h=true;
b-=arr[it].se;
}
if (h) continue;
for (auto it:S[b]) if (!has[it]){
has[it]=h=true;
a-=arr[it].fi;
}
if (h) continue;
for (auto it:B[b]) if (!has[it]){
has[it]=h=true;
a-=arr[it].se;
}
if (!h) break;
}
if (a*b==0) ans.pub(l);
}
cout<<sz(ans)<<endl;
for (auto it:ans) cout<<it<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |