Submission #1183030

#TimeUsernameProblemLanguageResultExecution timeMemory
1183030steveonalexCutting a Rectangle (BOI24_rectangle)C++20
0 / 100
0 ms324 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define MASK(i) (1ULL << (i)) #define GETBIT(mask, i) (((mask) >> (i)) & 1) #define ALL(v) (v).begin(), (v).end() ll max(ll a, ll b){return (a > b) ? a : b;} ll min(ll a, ll b){return (a < b) ? a : b;} ll gcd(ll a, ll b){return __gcd(abs(a), abs(b));} ll lcm(ll a, ll b){return abs(a) / gcd(a, b) * abs(b);} ll LASTBIT(ll mask){return (mask) & (-mask);} int pop_cnt(ull mask){return __builtin_popcountll(mask);} int ctz(ull mask){return __builtin_ctzll(mask);} int logOf(ull mask){return 63 - __builtin_clzll(mask);} mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);} template <class T1, class T2> bool maximize(T1 &a, T2 b){ if (a < b) {a = b; return true;} return false; } template <class T1, class T2> bool minimize(T1 &a, T2 b){ if (a > b) {a = b; return true;} return false; } template <class T> void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){ for(auto item: container) out << item << separator; out << finish; } template <class T> void remove_dup(vector<T> &a){ sort(ALL(a)); a.resize(unique(ALL(a)) - a.begin()); } void solve(){ int n; cin >> n; vector<pair<ll, ll>> a(n); for(int i = 0; i < n; ++i) cin >> a[i].first >> a[i].second; sort(ALL(a)); ll area = 0; for(auto i: a) area += 1LL * i.first * i.second; vector<ll> candidate; candidate.push_back(a.back().first); int ma = 0; for(pair<int, int> i: a) maximize(ma, i.second); candidate.push_back(ma); for(ll &i: candidate) { minimize(i, area / i); } remove_dup(candidate); vector<ll> ans; for(ll i: candidate){ ll goy = i; ll j = area / i; if (i * j != area) continue; multiset<pair<int, int>> S1, S2; for(pair<int, int> i: a){ S1.insert(i); S2.insert(make_pair(i.second, i.first)); } bool check = true; for(int it = 1; it <= n; ++it){ pair<int,int> tmp = *S1.rbegin(); if (tmp.first == i || tmp.first == j || tmp.second == i || tmp.second == j){ if (tmp.first == i || tmp.second == j){ if (tmp.first == i) j -= tmp.second; else i -= tmp.first; } else{ swap(tmp.first, tmp.second); swap(S1, S2); if (tmp.first == i) j -= tmp.second; else i -= tmp.first; } S1.erase(S1.find(tmp)); S2.erase(S2.find(make_pair(tmp.second, tmp.first))); continue; } tmp = *S2.rbegin(); if (tmp.first == i || tmp.first == j || tmp.second == i || tmp.second == j){ if (tmp.first == i || tmp.second == j){ if (tmp.first == i) j -= tmp.second; else i -= tmp.first; } else{ swap(tmp.first, tmp.second); swap(S1, S2); if (tmp.first == i) j -= tmp.second; else i -= tmp.first; } S2.erase(S2.find(tmp)); S1.erase(S1.find(make_pair(tmp.second, tmp.first))); continue; } check = false; break; } if (check) ans.push_back(goy); } cout << ans.size() << "\n"; printArr(ans); } int main(void){ ios::sync_with_stdio(0);cin.tie(0); cout.tie(0); clock_t start = clock(); solve(); cerr << "Time elapsed: " << clock() - start << "ms!\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...