제출 #1335484

#제출 시각아이디문제언어결과실행 시간메모리
1335484FIFI_cppCutting a rectangle (LMIO18_staciakampis)C++20
0 / 100
0 ms344 KiB
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <fstream>
#include <iterator>
#include <set>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <cctype>
#include <string>
#include <cassert>
#include <set>
#include <bitset>
#include <unordered_set>
#include <numeric>

#define all(a) a.begin(), a.end()
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ppi pair<int,pair<int,int>>
#define int int64_t

using namespace std;
//    /\_/\
//   (= ._.)
//   / >  \>
// encouraging cat
const int INF = 10000000000000000;
//const int mod = 1000000007;
const int mod = 998244353;
const int MAXN = 200005;
//ifstream fin('xor.in');
//ofstream fout('xor.out');
bool operator< (vector<int> x, vector<int> y)
{
    return x[0] * x[1] < y[0] * y[1];
}
int n;
vector<vector<int>> a;
bool check(int h, int w)
{
    bool ok = true;
    for (int i = 0;i < n;i++)
    {
        if (a[i][0] == h)
        {
            //h -= a[i][0];
            w -= a[i][1];
        }
        else if (a[i][0] == w)
        {
            //w -= a[i][0];
            h -= a[i][1];
        }
        else if (a[i][1] == h)
        {
            //h -= a[i][1];
            w -= a[i][0];
        }
        else if (a[i][1] == w)
        {
            //w -= a[i][1];
            h -= a[i][0];
        }
        else
        {
            ok = false;
            break;
        }
    }
    return ok;
}
signed main()
{
    cin >> n;
    a.resize(n, vector<int> (2, 0));
    int s = 0;
    for (int i = 0;i < n;i++)
    {
        cin >> a[i][0] >> a[i][1];
        s += a[i][0] * a[i][1];
    }
    sort(all(a));
    reverse(all(a));
    int h = a[0][0], w = s/h;
    vector<int> res;
    if (s % h == 0 && check(h, w))
    {
        res.pb(min(h, w));
    }
    h = a[0][1], w = s/h;
    if (s % h == 0 && check(h, w))
    {
        res.pb(min(h, w));
    }
    if (res.size() == 2 && res[0] == res[1])
    {
        res.pop_back();
    }
    cout << res.size() << '\n';
    sort(all(res));
    for (auto i: res)
    {
        cout << i << '\n';
    }
    cout << '\n';

    
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...