Submission #1304410

#TimeUsernameProblemLanguageResultExecution timeMemory
1304410BilAktauAlmansurCutting a Rectangle (BOI24_rectangle)C++20
0 / 100
19 ms572 KiB
#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];
vector<int> ga[N], gb[N];
void solve() {
    cin>>n;
    int area = 0;
    for(int i = 1; i <= n; i++) {
        cin>>p[i].fi>>p[i].se;
        ga[p[i].fi].push_back(i);
        gb[p[i].se].push_back(i);
        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);
            while(x && y) {
                if(x < y)swap(x, y);
                bool ok = 0;
                for(auto i : ga[x]) {
                    if(!us[i]) {
                        us[i] = 1;
                        y -= p[i].se;
                        ok = 1;
                        break;
                    }
                }
                if(ok)continue;
                for(auto i : gb[y]) {
                    if(!us[i]) {
                        us[i] = 1;
                        x -= p[i].fi;
                        ok = 1;
                        break;
                    }
                }
                if(!ok)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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...