제출 #974753

#제출 시각아이디문제언어결과실행 시간메모리
974753AdamGSCutting a rectangle (LMIO18_staciakampis)C++17
100 / 100
217 ms30308 KiB
#include<bits/stdc++.h> using namespace std; typedef long double ld; typedef long long ll; #define rep(a, b) for(int a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back #define all(a) a.begin(), a.end() set<pair<ll,ll>>A, B; vector<ll>ans; map<ll,ll>mp; ll sum; bool solve(ll x, ll y) { if(x<y) swap(x, y); if(y==0) return true; auto it=B.end(); --it; auto p=*it; it=A.end(); --it; auto q=*it; if(p.st>y || q.st>x) return false; if(p.st==y) { B.erase(p); A.erase({p.nd, p.st}); bool xd=solve(x-p.nd, y); B.insert(p); A.insert({p.nd, p.st}); return xd; } if(q.st==x) { A.erase(q); B.erase({q.nd, q.st}); bool xd=solve(x, y-q.nd); A.insert(q); B.insert({q.nd, q.st}); return xd; } it=A.lower_bound({y, -1}); if(it==A.end()) return false; auto r=*it; if(r.st!=y) return false; A.erase(r); B.erase({r.nd, r.st}); bool xd=solve(x-r.nd, y); A.insert(r); B.insert({r.nd, r.st}); return xd; } void check(ll x) { if(sum%x!=0) return; x=min(x, sum/x); if(mp.find(x)!=mp.end()) return; mp[x]=1; if(solve(x, sum/x)) ans.pb(x); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll k; cin >> k; vector<pair<ll,ll>>T(k); rep(i, k) { cin >> T[i].nd >> T[i].st; sum+=T[i].st*T[i].nd; A.insert({T[i].nd, T[i].st}); B.insert(T[i]); } sort(all(T)); check(T[k-1].st); rep(i, k) if(T[i].nd>T[k-1].st) check(T[i].nd); if(ans.size()==0) { cout << 0 << '\n'; return 0; } sort(all(ans)); vector<ll>P; P.pb(ans[0]); for(auto i : ans) if(P.back()!=i) P.pb(i); cout << P.size() << '\n'; for(auto i : P) cout << i << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...